question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SyntaxError: Cannot use import statement outside a module

See original GitHub issue

⚠️ IMPORTANT ⚠️ Please check the following list before proceeding. If you ignore this issue template, your issue will be directly closed.

  • Read the docs.
  • Use Vite >=2.0. (1.x is no longer supported)
  • If the issue is related to 1.x -> 2.0 upgrade, read the Migration Guide first.

Describe the bug

npm run dev failed to start

Reproduction

System Info

  • vite version: 2.0.0-beta.12
  • Operating System: window 10
  • Node version: 14.4.0
  • Package manager (npm/yarn/pnpm) and version: npm

Logs (Optional if provided reproduction)

PS C:\code\demo\vite-project> npm run dev

vite-project@0.0.0 dev C:\code\demo\vite-project vite

failed to load config from /code/demo/vite-project/vite.config.js error when starting dev server: C:\code\demo\vite-project\vite.config.js:1 import vue from ‘@vitejs/plugin-vue’ ^^^^^^

SyntaxError: Cannot use import statement outside a module at wrapSafe (internal/modules/cjs/loader.js:1116:16) at Module._compile (internal/modules/cjs/loader.js:1164:27) at Module._extensions…js (internal/modules/cjs/loader.js:1220:10) at Object.require.extensions.<computed> [as .js] (C:\code\demo\vite-project\node_modules_vite@2.0.0-beta.22@vite\dist\node\chunks\dep-30d01443.js:46937:13) at Module.load (internal/modules/cjs/loader.js:1049:32) at Function.Module._load (internal/modules/cjs/loader.js:937:14) at Module.require (internal/modules/cjs/loader.js:1089:19) at require (internal/modules/cjs/helpers.js:73:18) at loadConfigFromBundledFile (C:\code\demo\vite-project\node_modules_vite@2.0.0-beta.22@vite\dist\node\chunks\dep-30d01443.js:46941:17) at loadConfigFromFile (C:\code\demo\vite-project\node_modules_vite@2.0.0-beta.22@vite\dist\node\chunks\dep-30d01443.js:46888:32) npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! vite-project@0.0.0 dev: vite npm ERR! Exit status 1 npm ERR! npm ERR! Failed at the vite-project@0.0.0 dev script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\sl\AppData\Roaming\npm-cache_logs\2021-01-12T02_23_42_087Z-debug.log

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
userquincommented, Jul 6, 2021

@Akryum Try to just renaming your vite.config.js to vite.config.ts.

0reactions
Akryumcommented, Jul 6, 2021

I don’t understand 🙇

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught SyntaxError: Cannot use import statement outside ...
This means that you're using the native source code in an unaltered/unbundled state, leading to the following error: Uncaught SyntaxError: ...
Read more >
How to fix "cannot use import statement outside a module"
I stumbled on this error: Uncaught SyntaxError: cannot use import statement outside a module while importing a function from a JavaScript file.
Read more >
Cannot use import statement outside a module [React ...
When building a web application, you may encounter the SyntaxError: Cannot use import statement outside a module error.
Read more >
How to solve: cannot use import statement outside a module
When you see the error message Uncaught SyntaxError: cannot use import statement outside a module, it means you're using an import statement ......
Read more >
Cannot use import statement outside a module - Future Studio
A common error with modules is the “Uncaught SyntaxError: Cannot use import statement outside a module”. This error means you must ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found