allenhwkim / ngentest

Angular6+ Unit Test Generator For Components, Directive, Services, and Pipes
https://ngentest.github.io
MIT License
144 stars 60 forks source link

Getting error when trying to generate unit test #54

Closed puranjayjain closed 1 year ago

puranjayjain commented 2 years ago

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

allenhwkim commented 2 years ago

.mjs is not supported. I have never seen@augnlar/core served as .mjs format

puranjayjain commented 2 years ago

It happens with angular 13 @allenhwkim

robmasango commented 2 years ago

Hi I have the same error: Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@angular/common/fesm2015/http.mjs not supported. Instead change the require of node_modules/@angular/common/fesm2015/http.mjs to a dynamic import() which is available in all CommonJS modules. at Object. (: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. (/usr/local/lib/node_modules/ngentest/index.js:228:3) { code: 'ERR_REQUIRE_ESM' }

puranjayjain commented 2 years ago

Still facing this issue

jeniyakamble commented 2 years ago

getting error: Error [ERR_REQUIRE_ESM]: require() of ES Module node_modules/@angular/common/fesm2015/http.mjs not supported. Instead change the require of node_modules/@angular/common/fesm2015/http.mjs to a dynamic import() which is available in all CommonJS modules. at Object. (: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. (/usr/local/lib/node_modules/ngentest/index.js:228:3) { code: 'ERR_REQUIRE_ESM' }

Neizan93 commented 1 year ago

Same here

puranjayjain commented 1 year ago

This can indeed be fixed but would require a level of effort not possible by one person. If anyone here is willing to help me, we can fork it and do the following things:

  1. Bring the dependencies to the latest version
  2. ts parser and other parsers need to be adjusted according to angular 13 and 14.
  3. Drop support for older angular version pre 11.
PankajMSharma commented 1 year ago

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

XiaotianWU-code commented 1 year ago

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

hi, could you help me for this problem? Thanks

XiaotianWU-code commented 1 year ago

This can indeed be fixed but would require a level of effort not possible by one person. If anyone here is willing to help me, we can fork it and do the following things:

  1. Bring the dependencies to the latest version
  2. ts parser and other parsers need to be adjusted according to angular 13 and 14.
  3. Drop support for older angular version pre 11.

Hi, could you help me for this? Thanks

andrewscheiner commented 1 year ago

Hi, has anyone tried working on this issue? I am working on a project involving Angular unit tests and through some research came across this package. I would love to implement this into my development process but ran into the same issue as stated in the original issue in this thread. I made a fork of ngentest on another one of my accounts but I am new to Angular and I do not know how to solve the out of support issue on my own.

@puranjayjain @PankajMSharma @XiaotianWU-code @allenhwkim If any of you have made progress on adding Angular 13+ support for ngentest please let me know and I would love to help if at all possible. Thank you!

puranjayjain commented 1 year ago

@andrewscheiner I currently am using 13 and will upgrade to 16. I haven't integrated anything in 15+ so far but you can look at jest as it's now natively supported by angular.

andrewscheiner commented 1 year ago

@puranjayjain Ok so you are using Angular 13 and are suggesting that I look into using jest for Angular unit testing? I will do some research into Jest then. Do you happen to know if jest has any methods/functions which might be similar to what ngentest accomplishes?

puranjayjain commented 1 year ago

Unfortunately not. @andrewscheiner also I would say look into jest but it only works with angular 15+. Since you're starting out I'd highly recommend going with angular 16 as it is a massive update.

allenhwkim commented 1 year ago

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