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

[QUESTION]: production crashes on Windows instance #15

Open
simplecommerce opened this issue Oct 1, 2024 · 8 comments
Open

[QUESTION]: production crashes on Windows instance #15

simplecommerce opened this issue Oct 1, 2024 · 8 comments

Comments

@simplecommerce
Copy link

Hi,

I am testing the build for production on both Linux and Windows.
The same build runs perfectly on Linux (NGINX).
But on Windows, when I attempt to load the site, it crashes with this error:

C:\Users\chink\Downloads\core-vite-ts\dist>node main.cjs
Server running at http://localhost:3000
Creating Websocket Server
Creating wsClient. wss://kheang-backend.simplecommerce.com:4000
wsClient attempting to connect to GraphQL subscription server.
wsClient connected to GraphQL subscription server.
Error: ENOENT: no such file or directory, scandir 'C:\Users\chink\Downloads\core-vite-ts\client'
    at readdirSync (node:fs:1515:26)
    at totalist (file:///C:/Users/chink/Downloads/core-vite-ts/dist/server/build-AEWSNMSS.mjs:19:17)
    at module.exports (file:///C:/Users/chink/Downloads/core-vite-ts/dist/server/build-AEWSNMSS.mjs:646:9)
    at serveStaticFiles (file:///C:/Users/chink/Downloads/core-vite-ts/dist/server/index.mjs:15166:26)
    at async handler (file:///C:/Users/chink/Downloads/core-vite-ts/dist/server/index.mjs:15137:25) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'C:\\Users\\chink\\Downloads\\core-vite-ts\\client'
} Uncaught Exception thrown

I am using Windows NODE (Azure Web App environment).
I cannot load the dist/server/index.mjs because it gives me this error:

Error [ERR_REQUIRE_ESM]: require() of ES Module C:\home\site\wwwroot\dist\server\index.mjs not supported.
Instead change the require of C:\home\site\wwwroot\dist\server\index.mjs to a dynamic import() which is available in all CommonJS modules.
    at Module.patchedRequire (C:\PROGRA~2\SITEEX~1\NODEAP~1\210~1.4\nodejs\node_modules\diagnostic-channel\dist\src\patchRequire.js:16:46)
    at Hook._require.Module.require (C:\PROGRA~2\SITEEX~1\NODEAP~1\210~1.4\nodejs\node_modules\require-in-the-middle\index.js:188:39)
    at Object.<anonymous> (C:\Program Files\iisnode\interceptor.js:459:1)

So in order to bypass this, I created a main.cjs file in my wwwroot with the following:

// this file is only used on production deployment
import("./dist/server/index.mjs");

This worked in my previous setup which I was using vite standalone plugin with vavite.
But on vike-node I get the crash error.

It works if I move my main.cjs from the root, to the dist/server folder and change my import.

I assume its a configuration issue?
Any help is appreciated.

@brillout
Copy link
Member

brillout commented Oct 4, 2024

It's a limitation of older Node.js versions: you cannot load ESM from CJS.

Update your Node.js version, follow the recommendation provided by Node.js, or use ESM instead of CJS.

Closing as this isn't related to vike-node nor do I see potential for vike-node to improve DX regarding this Node.js behavior.

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale Oct 4, 2024
@simplecommerce
Copy link
Author

@brillout I understand about the ESM issue, my question wasn't related to that specifically, the issue wasn't node or my version since I am using Node v20, the issue is the path error:

Error: ENOENT: no such file or directory, scandir 'C:\Users\chink\Downloads\core-vite-ts\client'

For some reason, when I do my workaround to load ESM modules and the file is located in my root folder instead of inside dist/server it causes a path issue when it tries to publish the client assets from what I can understand when I debugged.
I didn't have this issue when I was using the previous suggested vavite + vite-plugin-standalone to do the same thing.

@brillout
Copy link
Member

brillout commented Oct 4, 2024

I ain't sure I understand. Minimal reproduction welcome.

@brillout
Copy link
Member

brillout commented Oct 4, 2024

at readdirSync (node:fs:1515:26)

This doesn't come from Vike nor vike-node, so I'm inclined to think it's a user-land issue not a vike(-node) one.

@simplecommerce
Copy link
Author

I ain't sure I understand. Minimal reproduction welcome.

Here is a working repo: https://github.com/simplecommerce/vike-node-example

You can clone and npm i.

Then simply run

node index.cjs from the root, and try to load the page, it will crash.

If you run node dist/server/index.cjs and load the page, it will run fine.

Both cjs files are created by me as a workaround to load the index.mjs. It was a suggestion I found online to run ESM on iis-node.

@brillout
Copy link
Member

brillout commented Oct 4, 2024

Indeed, I can reproduce. It seems like sirv is having issues.

@brillout brillout reopened this Oct 4, 2024
@brillout
Copy link
Member

brillout commented Oct 7, 2024

@simplecommerce I'm taking some time to work on this as I guess it isn't a blocker. If you disable standalone mode I expect the error to go away. But feel free to let me know if it's a blocker for you to disable standalone mode.

@simplecommerce
Copy link
Author

@simplecommerce I'm taking some time to work on this as I guess it isn't a blocker. If you disable standalone mode I expect the error to go away. But feel free to let me know if it's a blocker for you to disable standalone mode.

No problem, I can't disable standalone mode, but it isn't really a blocker since there is a workaround by moving the file in the dist/server folder until its fixed, so no worries, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants