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

[V3] Failed to parse source for import analysis when dynamic import has comment #8918

Closed
7 tasks done
huijiewei opened this issue Jul 4, 2022 · 1 comment · Fixed by #9314
Closed
7 tasks done
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)

Comments

@huijiewei
Copy link

Describe the bug

OK ->

import(`./mdx/${v}.mdx`).then((m) => {
  setMdx(m);
});

Wrong ->

import(/* webpackChunkName: 'docs' */ `./mdx/${v}.mdx`).then((m) => {
  setMdx(m);
});

Reproduction

https://stackblitz.com/edit/vitejs-vite-33fr4f?file=src%2FApp.tsx&terminal=dev

System Info

"@mdx-js/rollup": "^2.1.2",
"@types/react": "^18.0.14",
"@types/react-dom": "^18.0.5",
"@vitejs/plugin-react": "^2.0.0-beta.0",
"typescript": "^4.6.4",
"vite": "^3.0.0-beta.6"

Used Package Manager

npm

Logs

[plugin:vite:import-analysis] Failed to parse source for import analysis because the content contains invalid JS syntax. If you are using JSX, make sure to name the file with the .jsx or .tsx extension.
/home/projects/vitejs-vite-33fr4f/src/App.tsx:83:3
81 | }, 30);
82 | }
83 | }
| ^
84 |
at formatError (file:///home/projects/vitejs-vite-33fr4f/node_modules/vite/dist/node/chunks/dep-c7f6d0a5.js:35002:46)
at TransformContext.error (file:///home/projects/vitejs-vite-33fr4f/node_modules/vite/dist/node/chunks/dep-c7f6d0a5.js:34998:19)
at TransformContext.transform (file:///home/projects/vitejs-vite-33fr4f/node_modules/vite/dist/node/chunks/dep-c7f6d0a5.js:39908:22)
at async Object.transform (file:///home/projects/vitejs-vite-33fr4f/node_modules/vite/dist/node/chunks/dep-c7f6d0a5.js:35247:30)
at async loadAndTransform (file:///home/projects/vitejs-vite-33fr4f/node_modules/vite/dist/node/chunks/dep-c7f6d0a5.js:37701:29
Click outside or fix the code to dismiss.
You can also disable this overlay by setting server.hmr.overlay to false in vite.config.js.

Validations

@sapphi-red sapphi-red added the p3-minor-bug An edge case that only affects very specific usage (priority) label Jul 4, 2022
@bluwy
Copy link
Member

bluwy commented Jul 5, 2022

Went down the rabbithole and it seems like a bug in es-module-lexer: guybedford/es-module-lexer#118. If it's intended behaviour, I have a branch that should fix it, but waiting for the upstream issue for now.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants