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

(v6) ssrLoadModule error doesn't show log for each import #17810

Open
7 tasks done
hi-ogawa opened this issue Aug 2, 2024 · 3 comments
Open
7 tasks done

(v6) ssrLoadModule error doesn't show log for each import #17810

hi-ogawa opened this issue Aug 2, 2024 · 3 comments

Comments

@hi-ogawa
Copy link
Collaborator

hi-ogawa commented Aug 2, 2024

Describe the bug

On v5, when error occurs during ssrLoadModule, it logs error for each import from entry to where the error happened, for example:

$ node repro.mjs
1:11:30 PM [vite] Error when evaluating SSR module /src/dep3.js:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at instantiateModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11)

1:11:30 PM [vite] Error when evaluating SSR module /src/dep2.js:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at instantiateModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11)

1:11:30 PM [vite] Error when evaluating SSR module /src/dep1.js:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at instantiateModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11)

1:11:30 PM [vite] Error when evaluating SSR module /src/entry:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at instantiateModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/chunks/dep-mCdpKltl.js:52650:11)

This is not the case on v6 and the error would look like:

$ node repro.mjs
1:12:18 PM [vite] (ssr) Error when evaluating SSR module /src/entry:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at ESModulesEvaluator.runInlinedModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:1065:6)
    at ModuleRunner.directRequest (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:1038:82)
    at ModuleRunner.cachedRequest (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:947:28)
    at request (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:984:116)
    at async eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep2.js:3:44)
    at async ESModulesEvaluator.runInlinedModule (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:1057:5)
    at async ModuleRunner.directRequest (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:1038:61)
    at async ModuleRunner.cachedRequest (file:///home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/node_modules/.pnpm/[email protected]/node_modules/vite/dist/node/module-runner.js:948:76)
    at async eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep1.js:3:44)

There is a similar information available in stacktrace, but it's probably limited what it can show. I'm wondering whether v6 should do similar logging (though error logs on v5 can be too verbose so maybe that should be discussed as well).

Reproduction

https://github.com/hi-ogawa/reproductions/tree/main/vite-v6-ssr-error

Steps to reproduce

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    vite: 6.0.0-alpha.19 => 6.0.0-alpha.19

Used Package Manager

pnpm

Logs

No response

Validations

@sapphi-red
Copy link
Member

I think the new behavior is fine.

One thing that might be good to improve would be to remove ESModulesEvaluator.runInlinedModule/ModuleRunner.directRequest/ModuleRunner.cachedRequest/request from the stacktrace.
Then the stacktrace will be like:

$ node repro.mjs
1:12:18 PM [vite] (ssr) Error when evaluating SSR module /src/entry:
|- Error: something bad
    at eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep3.js:3:20)
    at async eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep2.js:3:44)
    at async eval (/home/hiroshi/code/personal/reproductions/vite-v6-ssr-error/src/dep1.js:3:44)

@sapphi-red
Copy link
Member

Hmm, it seems fixStacktrace: true is not working in this repro.
The following error happens if I add , { fixStacktrace: true } to server.ssrLoadModule.

 node repro.mjs
Error: `line` must be greater than 0 (lines start at line 1)
    at async ModuleLoader.import (https://vbwimjlralgithub-3s0r.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:154:2688)
    at async loadESM (https://vbwimjlralgithub-3s0r.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:184:541)
    at async handleMainPromise (https://vbwimjlralgithub-3s0r.w-credentialless-staticblitz.com/builtins.ddb8d84d.js:165:296)

@hi-ogawa
Copy link
Collaborator Author

The broken stack might be due to stackblitz's runtime? stackblitz/webcontainer-core#1240

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

No branches or pull requests

2 participants