jest-preset-angularng-mocks

ng-mocks giving error about imports with jest-preset-angular


Using ng-mocks 13.5.2 with jest-preset-angular 12 and @ngneat/spectator 11 I am getting the below error any time I try to use MockComponents or MockPipe in my spec file.

I'm not sure why this is happening.

Must use import to load ES Module: /Users/scott/ltr/ltr/node_modules/@angular/core/fesm2020/core.mjs.

at Runtime.requireModule (node_modules/jest-runtime/build/index.js:1011:21)
at node_modules/ng-mocks/webpack:/ng-mocks/webpack/universalModuleDefinition:3:36
at Object.WEBPACK_EXTERNAL_MODULE__8900 (node_modules/ng-mocks/webpack:/ng-mocks/webpack/universalModuleDefinition:10:19)


Solution

  • The issue was reported and fixed, please use the latest version of ng-mocks: 14.0.1 or younger.

    The problem was triggered by the node's flag: --experimental-vm-modules, which forces to use imports instead of require, whereas ng-mocks hadn't provided an esm build.

    The fix was implemented here: