ngentest: Getting error when trying to generate unit test

I used the following command on a component and a guard file

ngentest some-guard.guard.ts

I got the following response

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/myuser/Code/app/node_modules/@angular/core/fesm2015/core.mjs not supported.
Instead change the require of /Users/myuser/Code/app/node_modules/@angular/core/fesm2015/core.mjs to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (<anonymous>:10:16)
    at requireFromString (/usr/local/lib/node_modules/ngentest/node_modules/require-from-string/index.js:28:4)
    at run (/usr/local/lib/node_modules/ngentest/index.js:159:21)
    at Object.<anonymous> (/usr/local/lib/node_modules/ngentest/index.js:228:3) {
  code: 'ERR_REQUIRE_ESM'
}

I’m using the following versions

node: v16.13.1 yarn: 1.22.15

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 15 (2 by maintainers)

Most upvoted comments

This is fixed by 1.5.0 release Remove Angular dependency by parsing code directly instead of using require-from-string #63

Please upgrade your command to 1.5.0, npm install ngentest@1.5.0 -D

@puranjayjain I can help with this. I have worked on similar things before.