angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open DineshChopra opened this issue 8 years ago • 38 comments

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)

[email protected] [~/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)

DineshChopra avatar May 05 '18 06:05 DineshChopra

Same here:

Angular CLI: 6.0.0 Node: 10.0.0 Ubuntu 16.04

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

tomash970 avatar May 05 '18 07:05 tomash970

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.

DineshChopra avatar May 05 '18 08:05 DineshChopra

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

ahnpnl avatar May 05 '18 10:05 ahnpnl

Same right here... but have seen that the last CLI command to update : rxjs-5-to-6-migrate -p src/tsconfig.app.json

doesn't work as expected. Indeed that throw an error :

Running the automatic migrations. Please, be patient and wait until the execution completes.
'C:\Users\Blair' n'est pas reconnu en tant que commande interne
ou externe, un programme ex�cutable ou un fichier de commandes.
child_process.js:644
    throw err;
    ^

Error: Command failed: C:\Users\Blair Jersyer\AppData\Roaming\npm\node_modules\rxjs-tslint\node_modules\.bin\tslint -c C:\Users\Blair Jersyer\AppData\Roaming\npm\node_modules\rxjs-tslint\rxjs-5-to-6-migrate.json -p src/tsconfig.app.json --fix

Should probably mention that, my Windows username has a space between "Blair Jersyer", does it have anything to do with ?

Blair2004 avatar May 06 '18 02:05 Blair2004

@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 ?

Blair2004 avatar May 06 '18 02:05 Blair2004

@Blair2004 it should be in dev deps (@angular-devkit).

casoetan avatar May 06 '18 07:05 casoetan

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...

superstator avatar May 06 '18 21:05 superstator

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

kylebradshaw avatar May 07 '18 13:05 kylebradshaw

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

shauvet avatar May 07 '18 14:05 shauvet

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.

superstator avatar May 07 '18 16:05 superstator

I think RxJS v6 has major changes from v5, v6 brings backwards compatibility package rxjs-compat that will keep your applications working, but you should refactor TypeScript code so that it doesn't depend on rxjs-compat. For the same run following npm install -g rxjs-tslint, rxjs-5-to-6-migrate -p src/tsconfig.app.json npm uninstall rxjs-compat for. Then npm install --force for bypass the node-sass issues. You'll have a broken node-sass install but everything else will still work. Now my existing angular 5 app is upgraded to angular 6.

krishragu12395 avatar May 08 '18 11:05 krishragu12395

I had the same issue I found that running the command to create the new project in PowerShell rather than Git Bash seemed to solve the problem for some reason.

JoA-MoS avatar May 09 '18 19:05 JoA-MoS

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

ken107 avatar May 25 '18 18:05 ken107

I recently helped someone debug this issue, problem ended up being an old yarn install he had forgotten about.

I had him uninstall yarn completely and attempt to ng new test-app

the next error made the problem obvious.

'yarn' is not recognized as an internal or external command, operable program or batch file. Package install failed, see above.

Had him set angular-cli package manager back to npm.

ng config -g cli.packageManager npm

and everything worked. Hope this helps someone.

sliceofbytes avatar May 27 '18 03:05 sliceofbytes

I have the same issue with @ken107, but I don't know why my NPM config had set to production if you have the same problem, you can check it by below command

Run npm config get production

https://stackoverflow.com/a/35098833/7291379

lichunbin814 avatar May 31 '18 02:05 lichunbin814

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.

craviteja avatar Jun 09 '18 06:06 craviteja

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

aeksco avatar Jun 19 '18 17:06 aeksco

All of the above answer are correct but they did not work for me. The only way I was able to make this work was by follow steps/commands

npm unistall -g @angular/[email protected] npm cache clean --force npm install -g @angular/[email protected] npm install node-sass -g ng new MY_PROJECT_NAME cp -r from_my_old_project to_new_MY_PROJECT_NAME

grepit avatar Jun 30 '18 06:06 grepit

Another issue could be with your dev-dependencies. Please check if they have been installed properly (check if they are availabe in the node_modules folder)

If not then a quick fix would be:

npm i --only=dev

Or check how your npm settings are regarding prod:

npm config get production

In case they are set to true - change them to false:

npm config set -g production false

and setup a new angular project.

Found that hint here: https://github.com/angular/angular-cli/issues/10661 (ken107 and lichunbin814)

Hope that helps.

princeV avatar Jun 30 '18 07:06 princeV

@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

shivymehta98 avatar Jul 01 '18 13:07 shivymehta98