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

Cannot run with vite-node #1309

Closed
CertainlyAria opened this issue Dec 3, 2023 · 5 comments
Closed

Cannot run with vite-node #1309

CertainlyAria opened this issue Dec 3, 2023 · 5 comments
Labels

Comments

@CertainlyAria
Copy link

Description

I tried to run the project with vite-node as suggested here but I get the following error.

Error: [vike@0.4.147][Bug] You stumbled upon a bug in Vike's source code. Go to https://github.com/vikejs/vike/issues/new and copy-paste this error; a maintainer will fix the bug (usually under 24 hours).
   at assertIsBrowser (file:///path-to-my-project/node_modules/.pnpm/vike@0.4.147_vite@5.0.0/node_modules/vike/dist/esm/utils/assertIsBrowser.js:5:5)
   at onLoad (file:///path-to-my-project/node_modules/.pnpm/vike@0.4.147_vite@5.0.0/node_modules/vike/dist/esm/client/server-routing-runtime/onLoad.js:4:5)
   at file:///path-to-my-project/node_modules/.pnpm/vike@0.4.147_vite@5.0.0/node_modules/vike/dist/esm/client/server-routing-runtime/utils.js:4:1
   at ViteNodeRunner.interopedImport (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:363:28)
   at ViteNodeRunner.directRequest (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:243:24)
   at ViteNodeRunner.cachedRequest (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:189:14)
   at ViteNodeRunner.dependencyRequest (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:223:12)
   at /path-to-my-project/src/vike/server:3:31
   at ViteNodeRunner.runModule (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:342:5)
   at ViteNodeRunner.directRequest (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:326:5)
   at ViteNodeRunner.cachedRequest (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:189:14)
   at ViteNodeRunner.executeFile (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:161:12)
   at CAC.run (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/cli.mjs:91:5)
 ELIFECYCLE  Command failed with exit code 1.

I'm on node v20.9.0 and pnpm v8.11.0. Minimal reproduction project can be found in this repo.

There two commands:

  • pnpm dev:vite-node produces the error
  • pnpm dev:tsx works without problem
@brillout
Copy link
Member

brillout commented Dec 3, 2023

at file:///path-to-my-project/node_modules/.pnpm/vike@0.4.147_vite@5.0.0/node_modules/vike/dist/esm/client/server-routing-runtime/utils.js:4:1
at ViteNodeRunner.interopedImport (file:///path-to-my-project/node_modules/.pnpm/vite-node@0.34.6_@types+node@20.9.2/node_modules/vite-node/dist/client.mjs:363:28)

It seems like vite-node is trying to import Vike's client entry 🤔

Any ideas why?

I'll have a closer look at it.

@brillout
Copy link
Member

brillout commented Dec 4, 2023

Running $ pnpm exec vite-node src/vike/server/index.ts instead of $ pnpm exec vite-node src/vike/server solves the issue, but vite-node now throws this:

Server running at http://localhost:3000
6:29:22 PM [vike][request(1)] HTTP request: /
6:29:22 PM [vike][request(1)][Warning] The 1st HTML variable is undefined which will be converted to an empty string, see render() hook defined by /src/vike/renderer/_default.page.server.jsx. Pass an empty string instead of undefined to remove this warning.
6:29:22 PM [vike][request(1)][Error] An error was thrown:
Error: The server is being restarted or closed. Request is outdated
    at throwClosedServerError (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vite@5.0.5/node_modules/vite/dist/node/chunks/dep-MF_y65BT.js:62744:17)
    at Object.resolveId (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vite@5.0.5/node_modules/vite/dist/node/chunks/dep-MF_y65BT.js:63169:21)
    at ModuleGraph.resolveId (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vite@5.0.5/node_modules/vite/dist/node/chunks/dep-MF_y65BT.js:59571:65)
    at ModuleGraph._resolveUrl (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vite@5.0.5/node_modules/vite/dist/node/chunks/dep-MF_y65BT.js:59293:57)
    at ModuleGraph.resolveUrl (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vite@5.0.5/node_modules/vite/dist/node/chunks/dep-MF_y65BT.js:59273:21)
    at file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vike@0.4.148_vite@5.0.5/node_modules/vike/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js:11:30
    at async Promise.all (index 0)
    at retrieveAssetsDev (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vike@0.4.148_vite@5.0.5/node_modules/vike/dist/esm/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.js:6:5)
    at getPageAssets (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vike@0.4.148_vite@5.0.5/node_modules/vike/dist/esm/node/runtime/renderPage/getPageAssets.js:19:21)
    at Object.__getPageAssets (file:///home/romu/tmp/vite-node-vite-bug/node_modules/.pnpm/vike@0.4.148_vite@5.0.5/node_modules/vike/dist/esm/node/runtime/renderPage/loadPageFilesServerSide.js:36:36) {
  code: 'ERR_CLOSED_SERVER'
}
6:29:22 PM [vike][request(1)][Warning] No _error.page.js found, we recommend defining an error page, see https://vike.dev/error-page
6:29:22 PM [vike][request(1)] HTTP response / ERR

I'm inclined to think it's more of a vite-node issue than a Vike one?

@brillout
Copy link
Member

brillout commented Dec 5, 2023

Closing because it seems that the issue is on vite-node's side. I'll re-open if there is evidence it's a Vike issue.

Consider using vavite instead of vite-node, check its vite-plugin-ssr examples.

@brillout brillout closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2023
@develohpanda
Copy link
Contributor

develohpanda commented Dec 29, 2023

I'm inclined to think it's more of a vite-node issue than a Vike one?

Hey @brillout, I got this working by snooping through the vite-node code and realizing it was closing the vite server because it was not set up in watch mode. By running vite-node --watch src/vike/server, I was able to progress past the Error: The server is being restarted or closed. Request is outdated error.

(I'm using the command vite-node --watch ./server/index.ts, with the filename and extension, and it works fine as well)

@brillout
Copy link
Member

@develohpanda Neat, thanks for sharing the solution.

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

No branches or pull requests

3 participants