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 use import statement outside a module" while using with nuxt-i18n

See original GitHub issue

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
mrazauskascommented, Jun 24, 2021

nuxt-i18n is published as ESM module. At the moment Jest needs additional configuration to be able to transpile it.

By default Jest transformers ignore node_modules directory. Jest throws an error, because it sees ESM syntax instead of expected CJS. To solve the issue nuxt-i18n should be included in the transformIgnorePatterns setting of Jest configuration:

transformIgnorePatterns: [
    'node_modules/(?!(nuxt-i18n)/)'
  ]
2reactions
mrazauskascommented, Jul 13, 2021

Here is the solution for multiple packages (adapted from Jest docs):

transformIgnorePatterns: [
  'node_modules/(?!(@nuxtjs/svg-sprite|nuxt-i18n)/)'
]
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 using nuxtjs ...
[Solved]-Cannot use import statement outside a module using nuxtjs-nuxt.js ... You need to mark vue-agile to be transpiled in order to work on...
Read more >
Javascript Fix Cannot Use Import Statement Outside A ...
Learn how to fix cannot use import statement outside a module error and successfully import function from another file in JavaScript.
Read more >
cannot use import statement outside a module - ItsJavaScript
json will tell Node you are using ES6 modules(es modules), which should get solve the error. If you would like to use the...
Read more >
How to fix SyntaxError: Cannot use import statement outside a ...
Introduction. When developing apps of scripts using Node JS you may encounter this error: SyntaxError: Cannot use import statement outside a module.
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