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

Internal server error: Cannot use 'import.meta' outside a module #53

Closed
vitorsemeano opened this issue May 3, 2023 · 3 comments · Fixed by #52 or #54
Closed

Internal server error: Cannot use 'import.meta' outside a module #53

vitorsemeano opened this issue May 3, 2023 · 3 comments · Fixed by #52 or #54

Comments

@vitorsemeano
Copy link

When upgrading from 1.2.7 to 1.3.x, I got the following error:

[vite] Internal server error: Cannot use 'import.meta' outside a module (1:0)

Further inspection, the error comes from using the lib acorn, saying that "import.meta" can't be used on scripts.

I am using a vite project with hmr. When running vite dev, vite will inject import.meta.hot in the compiled bundle. es-module-lexer will read the bundle and extract all imports, including import.meta.*. When you call acorn parse, you don't specify the sourceType, and the default value to that is 'script'. When it catches 'import.meta', it will throw this error.

Reverting to 1.2.7 solves this problem.

Possible solution would be to pass sourceType value as option of acorn.

@caoxiemeihao
Copy link
Contributor

sure right

@caoxiemeihao
Copy link
Contributor

I still hope you provide a minimal reproduction repo :)

@caoxiemeihao caoxiemeihao linked a pull request May 4, 2023 that will close this issue
@caoxiemeihao caoxiemeihao mentioned this issue May 4, 2023
@caoxiemeihao caoxiemeihao linked a pull request May 4, 2023 that will close this issue
@vitorsemeano
Copy link
Author

Hi, I see it's solved, but if you ever wanted to see the problem, here is the reproduction repo:

https://codesandbox.io/s/vite-react-forked-xw8suh

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

Successfully merging a pull request may close this issue.

2 participants