AlexKhymenko / ngx-permissions

Permission and roles based access control for your angular(angular 2,4,5,6,7,9+) applications(AOT, lazy modules compatible
MIT License
936 stars 126 forks source link

SyntaxError: Cannot use import statement outside a module #196

Open PhilippMeissner opened 2 years ago

PhilippMeissner commented 2 years ago

I'm submitting a...

[ ] Regression (a behavior that used to work and stopped working in a new release)
[x] Bug report
[ ] Feature request
[ ] Documentation issue or request

Current behavior

When running our tests with jest we receive the error SyntaxError: Cannot use import statement outside a module

C:\path-to-project\node_modules\ngx-permissions\fesm2015\ngx-permissions.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

Expected behavior

The import should just work as is.

Basically just create a new angular project with the given version below, add jest and jest-preset-angular. Additionally add and import the NgxPermissionsModule and run the tests.

Environment

Angular version: 12.2.3
ngx-permissions version: 13.0.1
jest version: 27.5.1
jest-preset-angular: 11.1.1
Node 12.16.3

To be perfectly honest I am not sure if this is a concern you can address or if it is something we need to change on our side. I tried adjusting the jest.config by adding mjs into moduleFileExtensions along with node_modules/(?!ngx-permissions) to transformIgnorePatterns definition.