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.

Cannot start nuxt: Cannot use import statement outside a module

See original GitHub issue

Hi,

Since yesterday Nuxt doesnt start with nuxt-graphql-client. Please check your Stackblitz from Quick Start, im getting the same error. https://stackblitz.com/edit/nuxt-graphql?file=README.md

package.json hasn’t change, I dont know how to roll back or what has changed.

cosmiconfig-typescript-loader has import { TypeScriptLoader } from "./loader"; but I dont see any recent changes in this repo

thank you

error:

 ERROR  (node:11056) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.                                                                                         08:49:58
(Use `node --trace-warnings ...` to show where the warning was created)


 ERROR  Cannot start nuxt:  Cannot use import statement outside a module                                                                                                                                        08:49:58

  import { TypeScriptLoader } from "./loader";
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
  at Object.compileFunction (node:vm:352:18)
  at wrapSafe (node:internal/modules/cjs/loader:1033:15)
  at Module._compile (node:internal/modules/cjs/loader:1069:27)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
  at Module.load (node:internal/modules/cjs/loader:981:32)
  at Function.Module._load (node:internal/modules/cjs/loader:822:12)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)


 ERROR  [unhandledRejection] Cannot use import statement outside a module                                                                                                                                       08:49:58  
  08:49:58

  import { TypeScriptLoader } from "./loader";
  ^^^^^^

  SyntaxError: Cannot use import statement outside a module
  at Object.compileFunction (node:vm:352:18)
  at wrapSafe (node:internal/modules/cjs/loader:1033:15)
  at Module._compile (node:internal/modules/cjs/loader:1069:27)
  at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
  at Module.load (node:internal/modules/cjs/loader:981:32)
  at Function.Module._load (node:internal/modules/cjs/loader:822:12)
  at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:170:29)
  at ModuleJob.run (node:internal/modules/esm/module_job:198:25)
  at async Promise.all (index 0)
  at async ESMLoader.import (node:internal/modules/esm/loader:385:24)

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
Diizzayycommented, Jul 29, 2022

@tasiotas @michtio @DenFin

This has been resolved. Be sure to upgrade the module to v0.1.7, delete the node_modules folder and your lockfile

1reaction
Diizzayycommented, Jul 29, 2022

@tasiotas @michtio @DenFin A quick update. We’ve narrowed it down to a strange ESM module resolution bug upstream in two different dependencies. A fix is on the way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot use import statement outside a module using nuxtjs
If you get an Cannot use import statement outside a module error, you may need to add your package to the build >...
Read more >
"Cannot use import statement outside a module" ( Nuxt.js ) · ...
Getting this error when using Nuxt.js. The component is wrapped in a client-only tag to avoid any SSR issues.
Read more >
Nuxt.js and Three.js production build - Cannot use import ...
Here i'm importing the plugins from the jsm folder, i have tried importing this from the js folder but then i get THREE...
Read more >
Getting error `Cannot use import statement outside a ...
That means whatever tool/framework you are using doesn't support ES Modules, so you would need to import the UMD files. This is a...
Read more >
Fix - Cannot use import statement outside module Error in Node
If you are using a node application and want to use the import statement, then you will also get the "Cannot use import...
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