我知道这个问题已经有了答案here,但是没有一个答案可以解决我的问题,我仍然可以得到堆栈跟踪信息:
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)
我的全局npm依赖项位于C:
中,但是我的项目文件夹和项目依赖项位于F:
我尝试过:
ng new
生成新应用,然后使用npm start/ng serve
启动它会产生相同的错误这是我的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"
}
}
答案 0 :(得分:1)
对于仍在寻找解决方案的人,我无法解决该问题,因此我寻求了一个相当简单的解决方案:我完全擦除了Windows并安装了Ubuntu 18,此后运行良好。
答案 1 :(得分:1)
在使用aspnetboilerplate的角度Ui时,我遇到了类似的问题
因此,我不使用“ npm”软件包管理器,而是使用yarn。
yarn add
我不知道为什么,但是它起作用了……甚至aspnetboilerplate的品牌也使用纱线##标题##
答案 2 :(得分:1)
首先运行以下命令-
npm install --save-dev @angular-devkit/build-angular
如果以上命令不起作用,则移至项目文件夹并运行此命令 命令:
npm install --save @angular-devkit/build-angular
如果您再次执行ng服务,但它不起作用,则只需在下面安装npm 命令
npm install
现在运行您的项目。它将起作用。
答案 3 :(得分:0)
问题是您的角度项目找不到构建项目所需的必需"@angular-devkit/build-angular"
依赖项。这由堆栈跟踪的这一部分指示:
从“ F:\ Documents \ ...”中找不到模块“ @ angular-devkit / build-angular”。
对于Windows,用户计算机上的F:驱动器是指辅助存储设备,而用户的主存储驱动器是C:驱动器。
我怀疑,因为您正在使用辅助存储来存储项目依赖项,所以缺少依赖项的原因可能是在C盘上错误安装了项目所需的node_modules
。也许出于某种原因,该模块可能已被意外从F驱动器中删除。无论哪种方式,无论您使用什么软件包管理器:npm / yarn ,都应该能够通过从F盘中项目根目录下载@angular-devkit/build-angular
依赖项来解决此错误。类似于:
cd <path_to_project_root>
npm i --save-dev @angular-devkit/build-angular
angular-cli明确尝试找到相对于当前目录的项目所需的node_modules
。在尝试构建/服务您的角度项目时,请记住这一点。无论您的软件包管理器是什么,您都需要为项目安装所有必需的依赖项。
希望有帮助!