Search code examples
angularangular-cli

ng version fails with error "Cannot find module ./package.json"


I tried to install Angular CLI for learning Angular on Node 23 with npm install -g @angular/cli . The install seemed successful but post install while trying to run the ng version command I receive the following error.

An unhandled exception occurred: Cannot find module './package.json'
Require stack:
- C:\Users\sudha\AppData\Roaming\npm\node_modules\@angular\cli\src\noop.js
See "C:\Users\sudha\AppData\Local\Temp\ng-C0Y4aA\angular-errors.log" for further details.

Upon checking the files, I see that noop.js doesn't exist and in the log file mentioned above I see

[error] Error: Cannot find module './package.json'
Require stack:
- C:\Users\sudha\AppData\Roaming\npm\node_modules\@angular\cli\src\noop.js
    at Function._resolveFilename (node:internal/modules/cjs/loader:1259:15)
    at Function._load (node:internal/modules/cjs/loader:1085:27)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)
    at Module.require (node:internal/modules/cjs/loader:1350:12)
    at require (node:internal/modules/helpers:138:16)
    at VersionCommandModule.run (C:\Users\sudha\AppData\Roaming\npm\node_modules\@angular\cli\src\commands\version\cli.js:46:28)
    at VersionCommandModule.handler (C:\Users\sudha\AppData\Roaming\npm\node_modules\@angular\cli\src\command-builder\command-module.js:154:39)

Could you please suggest a way to resolve this issue?


Solution

  • Angular only supports LTS versions of Node, see the docs. Try downgrading to Node v22.

    As a rule of thumb, you should only use even-numbered (18, 20, 22, ...) Node major versions. Odd-numbered (19, 21, 23, ...) Node major versions never enter LTS and won't be supported by Angular. For more information, see the Node.js Releases docs.