node.js 找不到模块“@angular-devkit/build-angular”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/50401665/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can not find module “@angular-devkit/build-angular”
提问by Brandon Lumsden
Using npm, I followed the getting started directions on the Angular CLI quick start page.
使用 npm,我遵循了 Angular CLI 快速入门页面上的入门指南。
Running ng serve --openafter creating and going into my new project "frontend" gave this error:
运行ng serve --open创造和进入我的新项目“前端”之后给了这个错误:
Could not find module "@angular-devkit/build-angular" from "C:\Users\Brandon\project-name\frontend".
Error: Could not find module "@angular-devkit/build-angular" from "C:\Users\Brandon\project-name\frontend".
at Object.resolve (C:\Users\Brandon\project-name\node_modules\@angular-devkit\core\node\resolve.js:141:11)
at Observable.rxjs_1.Observable [as _subscribe] (C:\Users\Brandon\project-name\node_modules\@angular-devkit\architect\src\architect.js:132:40)
I have tried suggestions from the other question similar to mine but it did not work. Answer was to run npm install --save-dev @angular-devkit/build-angular.
我已经尝试过来自与我类似的另一个问题的建议,但没有奏效。答案是跑npm install --save-dev @angular-devkit/build-angular。
I have also deleted modules, cleared cache, then did an install which also did not work.
我还删除了模块,清除了缓存,然后进行了安装,但也无法正常工作。
package.json:
包.json:
{
"name": "frontend",
"version": "0.0.0",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^6.0.2",
"@angular/common": "^6.0.2",
"@angular/compiler": "^6.0.2",
"@angular/core": "^6.0.2",
"@angular/forms": "^6.0.2",
"@angular/http": "^6.0.2",
"@angular/platform-browser": "^6.0.2",
"@angular/platform-browser-dynamic": "^6.0.2",
"@angular/router": "^6.0.2",
"core-js": "^2.5.4",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular/compiler-cli": "^6.0.2",
"@angular-devkit/build-angular": "~0.6.3",
"typescript": "~2.7.2",
"@angular/cli": "^6.0.3",
"@angular/language-service": "^6.0.2",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "~8.9.4",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~1.4.2",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1"
}
}
angular.json:
角度.json:
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"frontend": {
"root": "",
"sourceRoot": "src",
"projectType": "application",
"prefix": "app",
"schematics": {},
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/frontend",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.app.json",
"assets": [
"src/favicon.ico",
"src/assets"
],
"styles": [
"src/styles.css"
],
"scripts": []
},
"configurations": {
"production": {
"fileReplacements": [
{
"replace": "src/environments/environment.ts",
"with": "src/environments/environment.prod.ts"
}
],
"optimization": true,
"outputHashing": "all",
"sourceMap": false,
"extractCss": true,
"namedChunks": false,
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true
}
}
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"options": {
"browserTarget": "frontend:build"
},
"configurations": {
"production": {
"browserTarget": "frontend:build:production"
}
}
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "frontend:build"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "src/test.ts",
"polyfills": "src/polyfills.ts",
"tsConfig": "src/tsconfig.spec.json",
"karmaConfig": "src/karma.conf.js",
"styles": [
"src/styles.css"
],
"scripts": [],
"assets": [
"src/favicon.ico",
"src/assets"
]
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"src/tsconfig.app.json",
"src/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
},
"frontend-e2e": {
"root": "e2e/",
"projectType": "application",
"architect": {
"e2e": {
"builder": "@angular-devkit/build-angular:protractor",
"options": {
"protractorConfig": "e2e/protractor.conf.js",
"devServerTarget": "frontend:serve"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": "e2e/tsconfig.e2e.json",
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "frontend"
}
回答by baao
Running ng serve --open after creating and going into my new project "frontend" gave this error:
在创建并进入我的新项目“前端”后运行 ng serve --open 给出了这个错误:
After creating the project, you need to run
创建项目后,您需要运行
npm install
to install all the dependencies listed in package.json
安装 package.json 中列出的所有依赖项
回答by Victor Ifeanyi Ejiogu
I looked inside node_modulesand apparently, only dependencies are installed, not devDependencies. With the new NPM, we need to explicitly get the devDependencies:
我看了看node_modules,显然,只安装了依赖项,而不是 devDependencies。使用新的 NPM,我们需要明确获取 devDependencies:
npm i --only=dev
If you wish to install just the devkit:
如果您只想安装 devkit:
npm install @angular-devkit/build-angular
Joint idea with - ken107(github)
与 - ken107(github) 的联合想法
回答by Sumit Singh Deo
If you are using angular version 8 please run the below command to fix this issue.
如果您使用的是 angular 版本 8,请运行以下命令来解决此问题。
ng update @angular/cli @angular/core
回答by RMo
This worked for me: Type npm audit fixin the commandline. Afterwards I was able to use ng serve --openagain.
这对我npm audit fix有用:输入命令行。后来我又可以用ng serve --open了。
回答by kashif
npm install --save-dev @angular-devkit/build-angular
It's Install @angular-devkit/build-angular as dev dependency. This package is newly introduced in Angular 6.0
安装 @angular-devkit/build-angular 作为开发依赖项。这个包是在 Angular 6.0 中新引入的
回答by Prasad Shigwan
Install @angular-devkit/build-angular as dev dependency. This package is newly introduced in Angular 6.0
安装 @angular-devkit/build-angular 作为开发依赖项。这个包是在 Angular 6.0 中新引入的
npm install --save-dev @angular-devkit/build-angular
or,
或者,
yarn add @angular-devkit/build-angular --dev
回答by Prince V
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)
另一个问题可能与您的开发依赖项有关。请检查它们是否已正确安装(检查它们是否在 node_modules 文件夹中可用)
If not then a quick fix would be:
如果没有,那么快速修复将是:
npm i --only=dev
Or check how your npm settings are regarding prod:
或者检查你的 npm 设置是如何与 prod 相关的:
npm config get production
In case they are set to true - change them to false:
如果它们被设置为 true - 将它们更改为 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)
在这里找到提示:https: //github.com/angular/angular-cli/issues/10661(ken107 和 lichunbin814)
Hope that helps.
希望有帮助。
回答by Abdus Salam Azad
Use npm updateor,
Run `npm install --save-dev @angular-devkit/build-angular
使用npm update或运行`npm install --save-dev @angular-devkit/build-angular
`
`
回答by David Bedo
I had the same problem, as it did not installed
我有同样的问题,因为它没有安装
@angular-devkit/build-angular
@angular-devkit/build-angular
The answer which has worked for me was this:
对我有用的答案是:
npm i --only=dev
npm i --only=dev
回答by Adham Developer
I struggled with the same problem just a minute ago. My project was generated using the v 1.6.0 of angular-cli.
就在一分钟前,我还在为同样的问题苦苦挣扎。我的项目是使用 angular-cli 的 v 1.6.0 生成的。
npm update -g @angular/cli editing my package.json changing the line "@angular/cli": "1.6.0", to "@angular/cli": "^1.6.0", npm update did the trick.
npm update -g @angular/cli 编辑我的 package.json 将 "@angular/cli": "1.6.0" 行更改为 "@angular/cli": "^1.6.0",npm update 成功了。

