Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't make manual import work for me #8

Closed
hagaigold opened this issue Sep 23, 2023 · 16 comments
Closed

can't make manual import work for me #8

hagaigold opened this issue Sep 23, 2023 · 16 comments
Labels
bug Something isn't working

Comments

@hagaigold
Copy link

hagaigold commented Sep 23, 2023

a sample repo - https://github.com/hagaigold/temp-vite-telefunc

what I tried:

  • import './mydist/server/importBuild.cjs'
  • await import('./mydist/server/importBuild.cjs')
  • await import inside the _telefunc middleware

how to create:

  • pnpm i
  • set --outDir to something else, e.g. mydist
  • pnpm run build
  • delete node_modules
  • pnpm i
  • add manual import to server.js
  • pnpm run server:prod
> pnpm run server:prod

> @ server:prod C:\CodeW\vite_tele
> cross-env NODE_ENV=production node ./server

DEBUG: import build...

Server running at http://localhost:3001
Error: [@brillout/[email protected]][Wrong Usage] Cannot find server build. (Re-)build your app and try again. If you still get this error, then you may need to manually import the server build, see https://github.com/brillout/vite-plugin-import-build#manual-import
    at createErrorWithCleanStackTrace (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\utils\createErrorWithCleanStackTrace.js:9:15)
    at assertUsage (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\utils\assert.js:40:92)
    at loadServerBuild (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\loadServerBuild\index.js:37:29)
    at async loadGlobImporter (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\vite\loadTelefuncFilesWithVite.js:34:9)
    at async loadTelefuncFilesWithVite (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\vite\loadTelefuncFilesWithVite.js:10:45)
    at async loadTelefuncFiles (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc\loadTelefuncFiles.js:34:73)
    at async runTelefunc_ (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc.js:82:59)
    at async runTelefunc (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc.js:38:16)
    at async telefunc (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\telefunc.js:11:26)
    at async file:///C:/CodeW/vite_tele/server.js:24:26
@hagaigold
Copy link
Author

Windows 10 [Version 10.0.19045.3448]
Node v18.17.1

@brillout
Copy link
Owner

brillout commented Sep 23, 2023 via email

@hagaigold
Copy link
Author

hagaigold commented Sep 23, 2023

If I am "forcing" to skip the loadServerBuild function, the manual import is working.
from the comments inside, I assumed this is how it was in the past, loadServerBuild/index.ts:


  // We don't handle the following case:
  //  - When the user directly imports importBuild.cjs, because we assume that vite-plugin-ssr and Telefunc don't call loadServerBuild() in that case

  debugLogsRuntimePost({ success, requireError, isOutsideOfCwd, outDir })
  assertUsage(
    success,
    'Cannot find server build. (Re-)build your app and try again. If you still get this error, then you may need to manually import the server build, see https://github.com/brillout/vite-plugin-import-build#manual-import'
  )

@hagaigold
Copy link
Author

so, I assume the issue is from the calling module, Telefunc, and not from here- if this was the intention of the design.

@hagaigold
Copy link
Author

hagaigold commented Sep 24, 2023

vite-plugin-ssr / vike work as expected.

@brillout
Copy link
Owner

Apologies for the delay; I was in the middle of the Vike rename vike#736 which needed to be executed quickly. I'll have a look at this issue tomorrow.

@brillout
Copy link
Owner

I cannot reproduce on my Linux machine. I suspect the issue to be related to Windows.

Change line 5 of node_modules/.pnpm/@[email protected]/node_modules/@brillout/vite-plugin-import-build/dist/shared/debugLogs.js.

- const DEBUG = false;
+ const DEBUG = true;

Then report back the debug logs.

@brillout
Copy link
Owner

And, indeed, Telefunc should skip loadServerBuild() when you manually import dist/server/importBuild.cjs. But it should still work without you needing to manually import. The debug logs will shed light on why it doesn't work.

@brillout brillout added the bug Something isn't working label Sep 25, 2023
@hagaigold
Copy link
Author

> pnpm run server:prod                                                                                                                                                                                                             
                                                                                                                                                                                                                                   
> @ server:prod C:\CodeW\vite_tele                                                                                                                                                                                                 
> cross-env NODE_ENV=production node ./server                                                                                                                                                                                      
                                                                                                                                                                                                                                   
Server running at http://localhost:3001                                                                                                                                                                                            
[@brillout/[email protected]][DEBUG] DEBUG_LOGS_RUNTIME [begin]                                                                                                                                                      
[@brillout/[email protected]][DEBUG] process.platform "win32"                                                                                                                                                        
[@brillout/[email protected]][DEBUG] process.release {"name":"node","lts":"Hydrogen","sourceUrl":"https://nodejs.org/download/release/v18.17.1/node-v18.17.1.tar.gz","headersUrl":"https://nodejs.org/download/releas
e/v18.17.1/node-v18.17.1-headers.tar.gz","libUrl":"https://nodejs.org/download/release/v18.17.1/win-x64/node.lib"}                                                                                                                 
[@brillout/[email protected]][DEBUG] navigator undefined                                                                                                                                                             
[@brillout/[email protected]][DEBUG] cwd C:/CodeW/vite_tele                                                                                                                                                          
[@brillout/[email protected]][DEBUG] importer.status UNSET                                                                                                                                                           
[@brillout/[email protected]][DEBUG] requireError undefined                                                                                                                                                          
[@brillout/[email protected]][DEBUG] outDir undefined                                                                                                                                                                
[@brillout/[email protected]][DEBUG] isOutsideOfCwd null                                                                                                                                                             
[@brillout/[email protected]][DEBUG] success false                                                                                                                                                                   
[@brillout/[email protected]][DEBUG] DEBUG_LOGS_RUNTIME [end]                                                                                                                                                        
Error: [@brillout/[email protected]][Wrong Usage] Cannot find server build. (Re-)build your app and try again. If you still get this error, then you may need to manually import the server build, see https://github
.com/brillout/vite-plugin-import-build#manual-import                                                                                                                                                                               
    at createErrorWithCleanStackTrace (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\utils\createErrorWithCleanStackTrace.js:9:15)          
    at assertUsage (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\utils\assert.js:40:92)                                                    
    at loadServerBuild (C:\CodeW\vite_tele\node_modules\.pnpm\@[email protected]\node_modules\@brillout\vite-plugin-import-build\dist\loadServerBuild\index.js:39:29)                                       
    at async loadGlobImporter (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\vite\loadTelefuncFilesWithVite.js:34:9)                                                                   
    at async loadTelefuncFilesWithVite (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\vite\loadTelefuncFilesWithVite.js:10:45)                                                         
    at async loadTelefuncFiles (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc\loadTelefuncFiles.js:34:73)                                                           
    at async runTelefunc_ (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc.js:82:59)                                                                                  
    at async runTelefunc (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\runTelefunc.js:38:16)                                                                                   
    at async telefunc (C:\CodeW\vite_tele\node_modules\.pnpm\[email protected]\node_modules\telefunc\dist\cjs\node\server\telefunc.js:11:26)                                                                                         
    at async file:///C:/CodeW/vite_tele/server.js:24:26                                                                                                                                                                            

@hagaigold
Copy link
Author

But it should still work without you needing to manually import. The debug logs will shed light on why it doesn't work.

It does work without manually import with dist/server.
But fail with different build directory, e.g. mydist/server.

@hagaigold
Copy link
Author

I cannot reproduce on my Linux machine. I suspect the issue to be related to Windows.

on wsl2 same error:

> @ server:prod /home/hagai/stam/temp-vite-telefunc
> cross-env NODE_ENV=production node ./server

Server running at http://localhost:3001
[@brillout/[email protected]][DEBUG] DEBUG_LOGS_RUNTIME [begin]
[@brillout/[email protected]][DEBUG] process.platform "linux"
[@brillout/[email protected]][DEBUG] process.release {"name":"node","lts":"Hydrogen","sourceUrl":"https://nodejs.org/download/release/v18.18.0/node-v18.18.0.tar.gz","headersUrl":"https://nodejs.org/download/release/v18.18.0/node-v18.18.0-headers.tar.gz"}
[@brillout/[email protected]][DEBUG] navigator undefined
[@brillout/[email protected]][DEBUG] cwd /home/hagai/stam/temp-vite-telefunc
[@brillout/[email protected]][DEBUG] importer.status UNSET
[@brillout/[email protected]][DEBUG] requireError undefined
[@brillout/[email protected]][DEBUG] outDir undefined
[@brillout/[email protected]][DEBUG] isOutsideOfCwd null
[@brillout/[email protected]][DEBUG] success false
[@brillout/[email protected]][DEBUG] DEBUG_LOGS_RUNTIME [end]
Error: [@brillout/[email protected]][Wrong Usage] Cannot find server build. (Re-)build your app and try again. If you still get this error, then you may need to manually import the server build, see https://github.com/brillout/vite-plugin-import-build#manual-import
    at createErrorWithCleanStackTrace (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/@[email protected]/node_modules/@brillout/vite-plugin-import-build/dist/utils/createErrorWithCleanStackTrace.js:9:15)
    at assertUsage (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/@[email protected]/node_modules/@brillout/vite-plugin-import-build/dist/utils/assert.js:40:92)
    at loadServerBuild (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/@[email protected]/node_modules/@brillout/vite-plugin-import-build/dist/loadServerBuild/index.js:37:29)
    at async loadGlobImporter (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/vite/loadTelefuncFilesWithVite.js:34:9)
    at async loadTelefuncFilesWithVite (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/vite/loadTelefuncFilesWithVite.js:10:45)
    at async loadTelefuncFiles (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/server/runTelefunc/loadTelefuncFiles.js:34:73)
    at async runTelefunc_ (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/server/runTelefunc.js:82:59)
    at async runTelefunc (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/server/runTelefunc.js:38:16)
    at async telefunc (/home/hagai/stam/temp-vite-telefunc/node_modules/.pnpm/[email protected]/node_modules/telefunc/dist/cjs/node/server/telefunc.js:11:26)
    at async file:///home/hagai/stam/temp-vite-telefunc/server.js:24:26

@brillout
Copy link
Owner

I still can't reproduce on my Linux machine.

Note that you need to build your app before running pnpm run server:prod.

(Re-)build your app and try again.

If you do this:

rm -r mydist/ && pnpm run build && pnpm run server:prod

Does it work then? If it doesn't then I need the debug logs of this scenario. (Also you'll see debug logs when running pnpm run build which I'll need as well.)

Thanks, and apologies for the less than ideal DX. (FYI It's on the radar to completely get rid of @brillout/vite-plugin-import-build.)

@hagaigold
Copy link
Author

hagaigold commented Sep 30, 2023

I probably wasn't explained myself clear enough, sorry for that.

Does it work then?

The "normal" behavior is working as expected- if I (Re-)build all is well.

I try to test the manually import for a scenario which I build on machine A and run it on machine B (can't rebuild again on B)- hence the need for the manual import as explained here.

I still can't reproduce on my Linux machine.

Please try follow my scenario as I put on my OP: build (with --outDir), delete node_modules, pnpm i , manually import and then run without re-build

FYI It's on the radar to completely get rid of @brillout/vite-plugin-import-build.

I saw other potential issue but didn't want to overload this one.
If you think it is waste of time to fix something that you are going to remove- it is fine by me.
I don't need this fix. I just assumed you will want to know about those kinds of issues :)

@brillout
Copy link
Owner

It's actually already fixed.

indeed, Telefunc should skip loadServerBuild() when you manually import dist/server/importBuild.cjs.

This was fixed here. I just released a new version [email protected]. It should work but I didn't test the fix; let me know if you still run into issues.

I saw other potential issue but didn't want to overload this one. [...] I just assumed you will want to know about those kinds of issues :)

Yes, I do want to know about all issues.

I'm closing this ticket as I believe it's fixed. But, yes, feel free (and I encourage you to) bring my attention to other issues.

Btw. would sponsoring be something your company be up for?

Thanks for your patience (apologies for the slow turnaround; many urgent tickets came up at the same time in the last couple of days).

@hagaigold
Copy link
Author

This was fixed here. I just released a new version [email protected]

working with [email protected]

Btw. would sponsoring be something your company be up for?

I am currently only evaluating telefunc.
If in the future I will use it in projects that generates some income, I will definitely consider sponsoring.

@brillout
Copy link
Owner

brillout commented Oct 1, 2023

Makes sense 👍 thanks for considering sponsoring 🙏.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants