-
Notifications
You must be signed in to change notification settings - Fork 309
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
[Bug]: SyntaxError: Cannot use import statement outside a module #1149
Comments
You need to add
Angular 13 libraries are shipped under ESM format I believe, which now only contains |
Thanks, that seems to do the trick! |
FYI: The following pattern will not ignore (transform with jest-preset-angular) any transformIgnorePatterns: ['node_modules/(?!.*\\.mjs$)'] |
I think that pattern seems to be generic enough to add to the preset? |
@ahnpnl or @FrozenPandaz 's solution is not working for me. I am using Nx and angular 13. I have an angular library in the Nx workspace that utilizes the ngx-translate library which is working when I serve the app in the workspace but the libraries jest tests fail for the components using either the translate service or pipe. displayName: 'ui', preset: '../../jest.preset.js', setupFilesAfterEnv: ['/src/test-setup.ts'], globals: {
}, coverageDirectory: '../../coverage/libs/ui', transformIgnorePatterns: [
], transform: {
}, snapshotSerializers: [
], }; I have also tried specifying the path to node_modules as 'node_modules/(?!.\.mjs$)' and '/node_modules/(?!.\.mjs$)' also with no success. What I am seeing is anytime a components spec file references the @ngx-translate library at all in any way Jest will of course fail in parsing the .mjs file in the ngx-library with the error: |
@TCModus the workaround will be applicable to |
Hi all! |
@achilehero This is an issue with nx. Please follow the following issue: nrwl/nx#7844 |
Yes, thanks! I discovered that after I asked here. |
If anyone is still facing this error. I'm using Jest 28 and Angular 13 with jest-preset-angular 12 and the solution was having jest.config.js:
and then hopefully, all the .mjs files inside |
This is also a good lib to integrate Jest into your Angular project: https://www.npmjs.com/package/@angular-builders/jest |
upgraded to angular 14, and i have this problem:
` |
|
Only that works for me (ng13 + nx)
So you have to add |
@klevismehmeti how exactly did you manage to fix your issue with angular 14 |
I don't know if you're still struggling with this but the same thing was happening for me on Angular 15.0.4. I had to specify each module as they failed the test, like so:
|
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):
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 theAppComponent
. 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
The text was updated successfully, but these errors were encountered: