1

I am having issues with running the scripts for my sample angular app. The application was created with Nodejs 16.10.0 and npm version 6.23.2 with Angular CLI 14.2.10. I updated my nodejs to 16.13.0 and npm version 8.1.0. Angular CLI is 15.0.2. The issue is happening only with running my custom script. ng serve and ng build are working fine. Below is the error and I am unable to find the cause of the error.

I am trying to run the command npm run test:precheckin

Error:


> angular-app@0.0.0 test:precheckin
> npx npm-run-all build:int

Watching D:\angular migration POC\Angular14App\AngularApp and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./.angular ; is listed in .gitignore
Found & ignored ./.vscode ; is listed in .gitignore
Found & ignored ./dist ; is listed in .gitignore
Found & ignored ./node_modules ; is listed in .gitignore
Found & ignored ./src ; is listed in .gitignore
Found & ignored ./angular.json ; is listed in .gitignore
Found & ignored ./karma.conf.js ; is listed in .gitignore
Found & ignored ./package-lock.json ; is listed in .gitignore
Found & ignored ./package.json ; is listed in .gitignore
Found & ignored ./README.md ; is listed in .gitignore
Found & ignored ./tsconfig.app.json ; is listed in .gitignore
Found & ignored ./tsconfig.json ; is listed in .gitignore
Found & ignored ./tsconfig.spec.json ; is listed in .gitignore

Starting: test
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'D:\angular migration POC\Angular14App\AngularApp\test'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
Watching D:\angular migration POC\Angular14App\AngularApp and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./.angular ; is listed in .gitignore
Found & ignored ./.vscode ; is listed in .gitignore
Found & ignored ./dist ; is listed in .gitignore
Found & ignored ./node_modules ; is listed in .gitignore
Found & ignored ./src ; is listed in .gitignore
Found & ignored ./angular.json ; is listed in .gitignore
Found & ignored ./karma.conf.js ; is listed in .gitignore
Found & ignored ./package-lock.json ; is listed in .gitignore
Found & ignored ./package.json ; is listed in .gitignore
Found & ignored ./README.md ; is listed in .gitignore
Found & ignored ./tsconfig.app.json ; is listed in .gitignore
Found & ignored ./tsconfig.json ; is listed in .gitignore
Found & ignored ./tsconfig.spec.json ; is listed in .gitignore

Starting: build:int
node:internal/modules/cjs/loader:936
  throw err;
  ^

Error: Cannot find module 'D:\angular migration POC\Angular14App\AngularApp\build:int'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Package.json

{
  "name": "angular-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "watch": "ng build --watch --configuration int",
    "build:int": "npm run high:mem -- build --configuration=int",
    "test:precheckin": "npx npm-run-all test build:int",
    "high:mem": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng",
    "test": "ng test"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~13.3.0",
    "@angular/common": "~13.3.0",
    "@angular/compiler": "~13.3.0",
    "@angular/core": "~13.3.0",
    "@angular/forms": "~13.3.0",
    "@angular/platform-browser": "~13.3.0",
    "@angular/platform-browser-dynamic": "~13.3.0",
    "@angular/router": "~13.3.0",
    "rxjs": "~7.5.0",
    "tslib": "^2.3.0",
    "zone.js": "~0.11.4"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~13.3.10",
    "@angular/cli": "~13.3.10",
    "@angular/compiler-cli": "~13.3.0",
    "@types/jasmine": "~3.10.0",
    "@types/node": "^12.11.1",
    "jasmine-core": "~4.0.0",
    "karma": "~6.3.0",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage": "~2.1.0",
    "karma-jasmine": "~4.0.0",
    "karma-jasmine-html-reporter": "~1.7.0",
    "typescript": "~4.6.2"
  }
}
Konrad
  • 21,590
  • 4
  • 28
  • 64
GokuSS3
  • 123
  • 1
  • 11

1 Answers1

1

The problem is that npm-run-all doesn't seem to work with npx

See these discussions:

https://github.com/mysticatea/npm-run-all/issues/209

https://github.com/mysticatea/npm-run-all/issues/218

This looks like a good workaround https://github.com/mysticatea/npm-run-all/issues/209#issuecomment-847926286:

npx npm-run-all --npm-path npm other commands here

It would look like that:

"scripts": {
  // ...
  "test:precheckin": "npx npm-run-all --npm-path npm test build:int",
  // ...
},

But I would just install npm-run-all instead

npm install npm-run-all

and then

"scripts": {
  // ...
  "test:precheckin": "npm-run-all test build:int",
  // ...
},
Konrad
  • 21,590
  • 4
  • 28
  • 64
  • 1
    Thanks a lot. This fixed my problem. I didnt see there was a compatibility issue with npx and npm-run-all. I need the npx hence I had used the 1st one u suggested. – GokuSS3 Dec 16 '22 at 10:11