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

vite run using v0.22.1 gives "Cannot use 'import.meta' outside a module" #484

Closed
5 tasks done
rezelute opened this issue Aug 8, 2022 · 9 comments · Fixed by #486
Closed
5 tasks done

vite run using v0.22.1 gives "Cannot use 'import.meta' outside a module" #484

rezelute opened this issue Aug 8, 2022 · 9 comments · Fixed by #486
Labels
bug Something isn't working

Comments

@rezelute
Copy link

rezelute commented Aug 8, 2022

Describe the bug

Hi,
When compiling the vite project after updating to v0.22.1 (v0.22.0 works fine), I am getting the following error:

SyntaxError: Cannot use 'import.meta' outside a module
    at wrapSafe (internal/modules/cjs/loader.js:1001:16)
    at Module._compile (internal/modules/cjs/loader.js:1049:27)
    at Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
    at Object._require.extensions.<computed> [as .js] (.../vite/dist/node/chunks/dep-71eb12cb.js:62910:17)
    at Module.load (internal/modules/cjs/loader.js:950:32)
    at Function.Module._load (internal/modules/cjs/loader.js:790:12)
    at Module.require (internal/modules/cjs/loader.js:974:19)
    at require (internal/modules/cjs/helpers.js:101:18)
    at Object.<anonymous> (C:\...\unplugin-vue-components\dist\vite.js:3:24)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)

The Vite version is: 3.0.4. Let me know if I can provide anything else to help debug.

Reproduction

Use vite with v0.22.1

System Info

System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 AMD Ryzen 5 5600X 6-Core Processor
    Memory: 15.68 GB / 31.92 GB
  Binaries:
    Node: 14.20.0 - C:\Program Files\nodejs\node.EXE
    npm: 8.5.4 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Edge: Spartan (44.19041.1266.0), Chromium (103.0.1264.77)
    Internet Explorer: 11.0.19041.1566

Used Package Manager

npm

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.
@rezelute rezelute changed the title v0.22.1 introduces Cannot use 'import.meta' outside a module vite run using v0.22.1 gives "Cannot use 'import.meta' outside a module" Aug 8, 2022
@YujiaCheng1996
Copy link

YujiaCheng1996 commented Aug 9, 2022

same error in 0.22.2 vite3.

failed to load config from D:\...\vite.config.ts
error when starting dev server:
D:\...\node_modules\unplugin-vue-components\dist\chunk-YPBVGE6A.js:110
var _require = typeof _chunkEZUCZHGVjs.__require === "undefined" ? _module.createRequire.call(void 0, import.meta.url) : _chunkEZUCZHGVjs.__require;
                                                                                                             ^^^^

SyntaxError: Cannot use 'import.meta' outside a module
    at Object.compileFunction (node:vm:360:18)
    at wrapSafe (node:internal/modules/cjs/loader:1049:15)
    at Module._compile (node:internal/modules/cjs/loader:1084:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1174:10)
    at _require.extensions.<computed> [as .js] (file:///D:/.../node_modules/vite/dist/node/chunks/dep-71eb12cb.js:62910:17)
    at Module.load (node:internal/modules/cjs/loader:998:32)
    at Module._load (node:internal/modules/cjs/loader:839:12)
    at Module.require (node:internal/modules/cjs/loader:1022:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (D:\...\node_modules\unplugin-vue-components\dist\vite.js:3:24)

@yanbowe
Copy link

yanbowe commented Aug 9, 2022

same here v0.22.2

@savelifeme
Copy link

vite: ^2.7.2,
"unplugin-vue-components": "^0.22.2",

也同样报错

image

@JiatLn
Copy link

JiatLn commented Aug 9, 2022

rollback to ^0.21.2 is work

@atzcl
Copy link

atzcl commented Aug 9, 2022

No need to downgrade, you can temporarily add "type": "module" to package.json to fix the problem

@savelifeme
Copy link

^0.21.2

"unplugin-vue-components": "0.21.2",

真的管用啊哈哈哈,谢谢哈

image

@valcosmos
Copy link

@atzcl Thank u so much, it does work.

@fonghehe
Copy link

fonghehe commented Aug 9, 2022

same error,hope to resolve

sxzz added a commit that referenced this issue Aug 9, 2022
@sxzz sxzz added the bug Something isn't working label Aug 9, 2022
@antfu antfu closed this as completed in #486 Aug 9, 2022
@rezelute
Copy link
Author

rezelute commented Aug 9, 2022

Thank you for the fix 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants