[英]Can not find module “@angular-devkit/build-angular”
Using npm, I followed the getting started directions on the Angular CLI quick start page.使用 npm,我遵循了 Angular CLI 快速入门页面上的入门指南。
Angular CLI Quickstart Angular CLI 快速入门
Running ng serve --open
after 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"
}
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 中列出的所有依赖项
I looked inside node_modules
and apparently, only dependencies are installed, not devDependencies.我查看了
node_modules
内部,显然只安装了依赖项,而不是 devDependencies。 With the new NPM, we need to explicitly get the 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) 的联合想法
如果您使用的是 angular 版本 8,请运行以下命令来解决此问题。
ng update @angular/cli @angular/core
Use npm update
or, Run `npm install --save-dev @angular-devkit/build-angular使用
npm update
或运行 `npm install --save-dev @angular-devkit/build-angular
` `
npm install --save-dev @angular-devkit/build-angular
It's Install @angular-devkit/build-angular as dev dependency.
安装 @angular-devkit/build-angular 作为开发依赖项。 This package is newly introduced in Angular 6.0
这个包是在 Angular 6.0 中新引入的
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.希望有帮助。
This worked for me: Type npm audit fix
in the commandline.这对我
npm audit fix
:在命令行中输入npm audit fix
。 Afterwards I was able to use ng serve --open
again.之后我可以再次使用
ng serve --open
。
Using npm, I followed the getting started directions on the Angular CLI quick start page.使用 npm,我遵循了 Angular CLI 快速入门页面上的入门指南。
Angular CLI Quickstart Angular CLI 快速入门
Running ng serve --open
after 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"
}
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 成功了。
I've just encountered this problem and fixed it.我刚刚遇到了这个问题并修复了它。 I think the root cause of this problem is ng and current version of node.js (10.6.0) and accompanying npm are not in sync.
我认为这个问题的根本原因是 ng 和当前版本的 node.js (10.6.0) 和伴随的 npm 不同步。 I've installed the LTS version of node.js (8.11.3) and the problem disappeared.
我已经安装了 node.js (8.11.3) 的 LTS 版本,问题消失了。
D:project/contactlist npm install then D:project/contactlist ng new client D:project/contactlist npm install 然后 D:project/contactlist ng 新客户端
D:project/contactlist/client ng serve D:project/contactlist/client ng serve
this worked for me for some reason i had to delete the client folder and start npm install from the contactlist folder.由于某种原因,这对我有用,我不得不删除客户端文件夹并从联系人列表文件夹启动 npm install。 i tried every thing even clearing the cache and finally this worked.
我尝试了所有事情,甚至清除缓存,最后这奏效了。
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
did all the above didn't work... may be some issue with NPM以上所有方法都不起作用……可能是 NPM 的一些问题
Yarn
was helpful ..很有帮助..
Yarn Install
If you are updating from angular 7 to angular 8 then do this如果您要从 angular 7 更新到 angular 8,请执行此操作
ng update @angular/cli @angular/core
for more information read here https://github.com/just-jeb/angular-builders/blob/master/MIGRATION.MD有关更多信息,请阅读此处https://github.com/just-jeb/angular-builders/blob/master/MIGRATION.MD
Run the below command to get it resolved.运行以下命令以解决问题。 Whenever you pull a new project, few dependencies wont get added to the working directory.
每当你拉一个新项目时,很少有依赖项不会被添加到工作目录中。 Run the below command to get it resolved
运行下面的命令来解决它
npm install --save-dev @angular-devkit/build-angular npm install --save-dev @angular-devkit/build-angular
I tried all the possible commands listed above and none of them worked for me, Check if Package.json contain "@angular-devkit/build-angular" if not just install it using(in my case version 0.803.19 worked)我尝试了上面列出的所有可能的命令,但没有一个对我有用,检查Package.json 是否包含“@angular-devkit/build-angular”,如果不只是使用安装它(在我的情况下版本 0.803.19 工作)
npm i @angular-devkit/build-angular@0.803.19
npm i @angular-devkit/build-angular@0.803.19
Or checkout at npm website repositories for version selection或者在npm网站存储库中签出版本选择
Using npm, I followed the getting started directions on the Angular CLI quick start page.使用 npm,我遵循了 Angular CLI 快速入门页面上的入门指南。
Angular CLI Quickstart Angular CLI 快速入门
Running ng serve --open
after 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"
}
尝试安装 angular-devkit 来构建 angular 项目
npm install --save-dev @angular-devkit/build-angular
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.