angular-cli: Can't run any command

Versions

node -v v8.9.4
npm -v 5.6.0

Repro steps

installed new angular cli

npm install -g @angular/cli

Output

C:\Users\xxx\AppData\Roaming\npm\ng -> C:\Users\xxx\AppData\Roaming\npm\node_modules@angular\cli\bin\ng npm WARN @angular-devkit/schematics@0.0.49 requires a peer of @angular-devkit/core@0.0.26 but none is installed. You must install peer dependencies yourself. npm WARN @schematics/angular@0.1.14 requires a peer of @angular-devkit/core@0.0.26 but none is installed. You must install peer dependencies yourself. npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules@angular\cli\node_modules\fsevents): npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“win32”,“arch”:“x64”})

Observed behavior

I get the same error no matter what ng command I run 
ng --version
ng new app

> module.js:540
>     throw err;
>     ^
> 
> Error: Cannot find module '@angular-devkit/core'
>     at Function.Module._resolveFilename (module.js:538:15)
>     at Function.Module._load (module.js:468:25)
>     at Module.require (module.js:587:17)
>     at require (internal/module.js:11:18)
>     at Object.<anonymous> (C:\Users\xxx\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\tree\virtual.js:10:16)
>     at Module._compile (module.js:643:30)
>     at Object.Module._extensions..js (module.js:654:10)
>     at Module.load (module.js:556:32)
>     at tryModuleLoad (module.js:499:12)
>     at Function.Module._load (module.js:491:3)

Desired behavior

Mention any other details that might be useful (optional)

I tried to uninstall nodejs and npm and reinstall Also remove angular and reinstall npm uninstall -g angular/cli npm cache clean npm install -g @angular/cli

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 21 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Yesterday we put out several releases for minor version that should address this: 1.4.10, 1.5.6, 1.6.5 and 1.7.0-beta.1. We also locked down the devkit dependencies on 1.4.10 and 1.5.6 so this does not happen again if you choose to stay on older versions.

Updating to the latest version within the minor you’re using should fix this issue. For example, if you are on 1.5.1, updating to 1.5.6 should fix it.

You should not add @angular-devkit/core directly to your project, it will be installed as part of @angular/cli.

I’d like to remind everyone that you only have reproducible installs if you use a lockfile. Both NPM v5+ and Yarn support lockfiles. If your CI works one day but not the next and you did not change your code or package.json, it is likely because one of your dependencies had a bad release and you did not have a lockfile.

It is your responsibility as a library consumer to use lockfiles. No one wants to do a release with bugs but it sometimes happens, and the best we can do is to fix it as fast as possible with a new release. When you have a couple of thousand total dependencies it is only a matter of time until one of them has a bad release.

Looks like a dependency was removed somewhere. I worked around this by:

For local angular-cli: npm install @angular-devkit/core --save-dev For global angular-cli: npm install -g @angular-devkit/core

Edit: As discussed below, you should perhaps not use --save-dev here.

Hi. Sorry about that. We just released an emergency patch for the devkit and are working to release a patch for 1.4 and 1.5 that will fix this retroactively. After this we will re-release the CLI and the devkit.

Closing this as it will be fixed soon (in the next few hours).

@dolanmiu This is how I resolve the issue on my side.

I removed the Node Modules

rm -rf node_modules/

Updated my package.json

BEFORE


  "devDependencies": {
    "@angular/cli": "1.6.4",
    "@angular/compiler-cli": "^5.1.0",
    "@angular/language-service": "^5.1.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

AFTER


  "devDependencies": {
    "@angular/cli": "1.5.6",
    "@angular/compiler-cli": "^5.1.0",
    "@angular/language-service": "^5.1.0",
    "@types/jasmine": "~2.8.3",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "codelyzer": "^4.0.1",
    "jasmine-core": "~2.8.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~2.0.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.9.1",
    "typescript": "~2.5.3"
  }

Install

npm i

Its failing on our build machine too with CLI version 1.6.3. But once I added the @angular-devkit/core to the dev dependencies of our project’s package.json,it started working fine. Should we make this permanent and commit as part of our package.json file or the fix will be available so that we can continue using the existing one?

@raffy-dev I had exactly the same problem. Just did a npm install -g @angular/core and then npm install, and everything went fine (maybe just the latter would suffice).

Upgrade of the CLI to 1.5.6 solves the issue with the devkit/core and devkit/schematics dependencies, but the issue with the dry-run error persists:

Error: dryRunSink.commit(...).ignoreElements(...).concat is not a function
dryRunSink.commit(...).ignoreElements(...).concat is not a function

https://github.com/angular/angular-cli/issues/9194

I got it working yesterday with @NickToony solution but today I’m getting a different error “You seem to not be depending on “@angular/core”. This is an error.”

I also deleted my node_modules and updated my package.json to 1.5.6 and ran npm install but still getting same error.

@dolanmiu you have to update to 1.5.6 like I say in my comment.

Closed or not - my AWS CodeBuild and associated Pipeline is still broken. I tried the “global” fix suggested by @NickToony - but even after including that in my buildspec.yml, I’m still getting the same failure when it moves on to ‘ng build’.

So - what is the preferred / optimal fix, while we’re waiting for the emergency patch to propagate?

Thanks in advance!

@NickToony Tried your way, worked only in local cli