[Bug]: SyntaxError: Cannot use import statement outside a module

See original GitHub issue

Version

11.0.0-rc.2

Steps to reproduce

Steps to reproduce:

Expected behavior

No error

Actual behavior

After updating to @ngx-translate/core@14.0.0, I keep getting this error in my jest tests (application itself works fine):

C:\dev\prj\Angular13Test\node_modules\@ngx-translate\core\fesm2015\ngx-translate-core.mjs:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,jest){import * as i0 from '@angular/core';
                                                                                                                                           ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import { Component } from '@angular/core';
    > 2 | import {TranslateService} from '@ngx-translate/core';
        | ^
      3 |
      4 | @Component({
      5 |   selector: 'app-root',

      at Runtime.createScriptFromCode (node_modules/jest-runtime/build/index.js:1728:14)
      at Object.<anonymous> (src/app/app.component.ts:2:1)

Any idea what the issue might be? I also created a simple new Angular project, added ngx-translate + jest and added the TranslateService in the constructor of the AppComponent. It has the same issue.

Additional context

No response

Environment

System:
    OS: macOS 11.6
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
  Binaries:
    Node: 14.17.0 - /usr/local/bin/node
    Yarn: 1.19.1 - /usr/local/bin/yarn
    npm: 7.15.1 - /usr/local/bin/npm
  npmPackages:
    jest: ^27.3.1 => 27.3.1

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:14 (1 by maintainers)

github_iconTop GitHub Comments

5reactions
FrozenPandazcommented, Nov 9, 2021

FYI: The following pattern will not ignore (transform with jest-preset-angular) any .mjs files in node_modules which would better describe the growing set of packages with the new APF format in Angular 13.

transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)']
4reactions
ahnpnlcommented, Nov 9, 2021

I think that pattern seems to be generic enough to add to the preset?

Read more comments on GitHub >

github_iconTop Results From Across the Web

"Uncaught SyntaxError: Cannot use import statement outside ...
There are three ways to solve this:- · 1. The first: In the script, include type=module · 2. The second: In node.js, into...
Read more >
Cannot use import statement outside a module [React ...
In this article, we talked about the SyntaxError: Cannot use import statement outside a module error in TypeScript and JavaScript. This error ......
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 >
SyntaxError: Cannot use import statement outside a module
This error is one of the most common issue if you are trying to use ES6 features in your JavaScript project. For eg:...
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 >

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