angular-cli: ng-serve is not working - Could not find module "@angular-devkit/build-angular"

Versions

ng : 6.0.0 node : v8.9.0 npm : 6.0.0 Operating System : macOS

<!--
Output from: `ng --version`.
If nothing, output from: `node --version` and `npm --version`.
  Windows (7/8/10). Linux (incl. distribution). macOS (El Capitan? Sierra?)
-->

Repro steps

  • Step 1
  • Step 2
  • Step 3

I have created new project with angular-cli. ng new testapp cd testapp npm install ng serve

ng serve is not working. I found following error

Could not find module "@angular-devkit/build-angular" from "/Users/dic/workspace/projects/carpool".
Error: Could not find module "@angular-devkit/build-angular" from "/Users/dic/workspace/projects/carpool".
    at Object.resolve (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/usr/local/lib/node_modules/@angular/cli/node_modules/@angular-devkit/architect/src/architect.js:132:40)
    at Observable.subscribe (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:162:69)
    at DoOperator.call (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/tap.js:71:23)
    at Observable.subscribe (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/Observable.js:159:22)
    at /usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeTo.js:22:31
    at Object.subscribeToResult (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/util/subscribeToResult.js:7:45)
    at MergeMapSubscriber._innerSub (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:132:38)
    at MergeMapSubscriber._tryNext (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:129:14)
    at MergeMapSubscriber._next (/usr/local/lib/node_modules/@angular/cli/node_modules/rxjs/internal/operators/mergeMap.js:112:18)

dic@dic.local [~/workspace/projects/carpool]$ ng --version

So request you to please help me to resolve that issue

Observed behavior

<!-- Normally this includes a stack trace and some more information. -->

Desired behavior

Mention any other details that might be useful (optional)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 28
  • Comments: 38

Commits related to this issue

Most upvoted comments

@DineshChopra i’ve finally made this npm install @angular-devkit/build-angular and it worked. I’m wondering it sould be within the dev deps or not ?

I looked inside node_modules and apparently only dependencies are installed, not devDependencies. With the new NPM, we need to explicitly get the devDependencies:

npm i --only=dev

I encountered this issue when use ng update to upgrade from 5 to 6. After successfully upgraded, the app couldn’t start

I remove my repo. Create new project again ng new testapp cd testapp npm install ng serve

Its working for me know, but don’t know why its not working earlier. Either its a problem of angular-cli or its a problem of my system.

It waste my 3 hours. So please clarify what exactly we have to do when we face that kind of issue.

Please do below steps

  1. Delete node_modules and package-lock.json (if you have one)
  2. And npm install again.

Its will be work perfectly.

You can try rm -rf node_modules then reinstall npm i. This works for me.

I got this working by moving a few things around in package.json

I moved the following from devDependencies into dependencies:

@angular-devkit/build-angular
typescript
@angular/compiler-cli

My particular issue was builds passing locally on my development machine, but failing in my Jenkins CI pipeline. Using angular ^6.0.0, codebase generated with angular/cli and I was trying to run ng build. Moving those dependencies around seemed to do the trick, but I cannot speak to why those changes fixed the build

For myself, during an upgrade from an NG5 app, when I hit this issue I essentially deleted my package-json.lock file and removed my node_modules dir and then npm i again and it worked. @superstator was right though the issue is in the package-lock.json file if you’re upgrading from NG5

Was running into this, and it ended up being a mismatch between the version of rxjs in package-lock.json and my installed version. Updated all my machines to 6.1 with npm i -g rxjs and am able to build and run again. Supremely unhelpful error message, though…

FWIW, I wasn’t upgrading an old project. I started a brand new project over the weekend on one machine (Win 10) and then checked it out and attempted to run on another (MacOS High Sierra). Both have brand new node installs, and @angular/cli 6.0, I just somehow ended up with rxjs 6.0 on one and 6.1 on the other, and the build was apparently flummoxed by the mismatched version.

I saw the crash both ways, too - the project was created with a reference to rxjs 6.0, and this crashed when I checked it out on the machine with rxjs 6.1. Somehow I managed to thrash around and upgrade the project without realizing it, and it started working on the 6.1 machine. Then I moved back to the original machine with 6.0 and it started crashing again, and I had to go take a break before I threw something out the window. I finally figured it out by nuking the entire project folder on the 6.0 machine, recreating from scratch with ng new, verifying that ran OK, and then stepping through the git diff until I narrowed it down to the rxjs version.

You can go for “npm install” everytime whenever you git pull some another app to your machine as the pushed code on the github is not having node modules.

On Sat, 9 Feb 2019, 12:55 pm Abdul R Nagori, notifications@github.com wrote:

I’m also facing the same issue : I installed and started a test app successfully. I git push it from a machine. Then I pulled it on another machine and now this issue occurs.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/10661#issuecomment-462021659, or mute the thread https://github.com/notifications/unsubscribe-auth/AlUswsGdBJSYDS4d8M-z1yLaGmAlqnaAks5vLnfSgaJpZM4Tzg0v .

npm i -D @angular-devkit/core it’s work

craviteja’s answer worked for me

delete node_modules/ and package-lock.json npm install

all better

Thanks npm install @angular-devkit/build-angular but i seem to run into another error

Versions of @angular/compiler-cli and typescript could not be determined. The most common reason for this is a broken npm install.

Please make sure your package.json contains both @angular/compiler-cli and typescript in devDependencies, then delete node_modules and package-lock.json (if you have one) and run npm install again.

Following the instructions in this thread https://github.com/angular/angular-cli/issues/8407

@Angular/cli 6.0.8 version : node -v :8.11.2 npm -v : 6.1.0 I was facing the below issue from 2 days and tried all possible solutions.

Local workspace file (‘angular.json’) could not be found. Error: Local workspace file (‘angular.json’) could not be found.

Solution : First confirm that you are there in a write folder where u have created a new file n downloaded angular.json . Do ng serve If still it doesn’t work Look inside node_modules…You must have only dependencies are installed n v need devDependencies Type npm i --only=dev