0

I know this question already has an answer here, however none of the answers fixed it for me, I still get that stack trace :

Could not find module "@angular-devkit/build-angular" from "F:\\Documents\\...".
Error: Could not find module "@angular-devkit/build-angular" from "F:\\Documents\\...".
    at Object.resolve (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\core\node\resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\src\architect.js:132:40)
    at Observable._trySubscribe (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:30:22)
    at C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:99:19
    at new Promise (<anonymous>)
    at Observable.toPromise (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:97:16)
    at ServeCommand.initialize (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:130:86)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)

My global npm dependencies are in C:, but my project folder and therefore project dependencies are in F:

I have tried :

  • Installing the module with npm both locally and globaly
  • Deleting package-lock, local node_modules, global node_modules and npm-cache
  • Uninstalling then installing node
  • Generating a new app with ng new, then launching it with npm start/ng serve produces the same error

Here is my package.json :

{
  "name": "...",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prod": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.1.0",
    "@angular/cdk": "^7.2.1",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "~7.1.0",
    "@angular/core": "~7.1.0",
    "@angular/flex-layout": "^7.0.0-beta.23",
    "@angular/forms": "~7.1.0",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "core-js": "^2.6.2",
    "moment": "^2.23.0",
    "ngx-moment": "^3.3.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "^0.8.27"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.1",
    "@angular-devkit/core": "^7.2.1",
    "@angular/cli": "~7.2.1",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "~4.5.0",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~3.1.1",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~1.1.2",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "~5.4.0",
    "ts-node": "~7.0.0",
    "tslint": "~5.11.0",
    "typescript": "~3.1.6"
  }
}
TheWildHealer
  • 1,546
  • 1
  • 15
  • 26

4 Answers4

3

The issue is your angular project can't find the required "@angular-devkit/build-angular" dependency necessary to build your project. This is indicated by this section of your stack trace:

Could not find module "@angular-devkit/build-angular" from "F:\Documents\...".

For Windows, the F: drive on a user's computer refers to a secondary storage device while a user's main storage drive is the C: drive.

I suspect, since you're using a secondary storage for your project dependencies, the reason for the missing dependency could be an erroneous installation of your project's required node_modules on your C drive. Perhaps for one reason or another, this module could've been accidentally deleted from the F drive. Either way, regardless of your package manager: npm/yarn, you should be able to resolve this error by downloading the @angular-devkit/build-angular dependency from your project's root directory within your F drive. Something along the lines of:

cd <path_to_project_root> 
npm i --save-dev @angular-devkit/build-angular

The angular-cli explicitly tries to find your project's required node_modules relative to the current directory. Keep this in mind when trying to build/serve your angular project. Regardless of your package manager you will need to have installed all the necessary dependencies for your project.

Hopefully that helps!

Nathan
  • 7,853
  • 4
  • 27
  • 50
3

First of all run the following command -

npm install --save-dev @angular-devkit/build-angular

If the above command does not work, then move to the project folder and run this command:

npm install --save @angular-devkit/build-angular

If again you doing ng serve and its not working then just install npm by below command

npm install

Now run your project. It will work.

nick
  • 425
  • 4
  • 12
1

I had a similar issue ..while working with angular Ui of aspnetboilerplate

so Instead of using 'npm' package manager I user yarn.

yarn add 

I dont know why but it worked ... even the makes at aspnetboilerplate use yarn ## Heading ##

Rohit Kumar
  • 1,777
  • 2
  • 13
  • 26
-4

For whoever still looking for a solution, I couldn't fixed the problem, therefore I went for a rather simple solution : I completely wiped Windows and installed Ubuntu 18, works fine since then

TheWildHealer
  • 1,546
  • 1
  • 15
  • 26