找不到模块“ @ angular-devkit / build-angular”


446

更新到Angular 6.0.1后,出现以下错误ng serve

Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
Error: Could not find module "@angular-devkit/build-angular" from "/home/Projects/myProjectName".
    at Object.resolve (/home/Projects/myProjectName/node_modules/@angular-devkit/core/node/resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (/home/Projects/myProjectName/node_modules/@angular-devkit/architect/src/architect.js:132:40)

ng update说一切都井井有条。删除node_modules文件夹和全新npm install安装也无济于事。

我的项目基于ng2-admin(Angular4版本)。这是我的package.json依赖项:

 "dependencies": {
    "@angular/animations": "^6.0.1",
    "@angular/common": "^6.0.1",
    "@angular/compiler": "^6.0.1",
    "@angular/core": "^6.0.1",
    "@angular/forms": "^6.0.1",
    "@angular/http": "^6.0.1",
    "@angular/platform-browser": "^6.0.1",
    "@angular/platform-browser-dynamic": "^6.0.1",
    "@angular/platform-server": "^6.0.1",
    "@angular/router": "^6.0.1",
    "@ng-bootstrap/ng-bootstrap": "1.0.0-alpha.26",
    "@ngx-translate/core": "^10.0.1",
    "@ngx-translate/http-loader": "^3.0.1",
    "amcharts3": "github:amcharts/amcharts3",
    "ammap3": "github:amcharts/ammap3",
    "angular-table": "^1.0.4",
    "angular2-csv": "^0.2.5",
    "angular2-datatable": "0.6.0",
    "animate.css": "3.5.2",
    "bootstrap": "4.0.0-alpha.6",
    "bower": "^1.8.4",
    "chart.js": "1.1.1",
    "chartist": "0.10.1",
    "chroma-js": "1.3.3",
    "ckeditor": "4.6.2",
    "core-js": "2.4.1",
    "easy-pie-chart": "2.1.7",
    "font-awesome": "4.7.0",
    "fullcalendar": "3.3.1",
    "google-maps": "3.2.1",
    "ionicons": "2.0.1",
    "jquery": "3.2.1",
    "jquery-slimscroll": "1.3.8",
    "leaflet": "0.7.7",
    "leaflet-map": "0.2.1",
    "lodash": "4.17.4",
    "ng2-ckeditor": "1.1.6",
    "ng2-completer": "^1.6.3",
    "ng2-handsontable": "^2.1.0-rc.3",
    "ng2-slim-loading-bar": "^4.0.0",
    "ng2-smart-table": "^1.0.3",
    "ng2-tree": "2.0.0-alpha.5",
    "ngx-uploader": "4.2.4",
    "normalize.css": "6.0.0",
    "roboto-fontface": "0.7.0",
    "rxjs": "^6.1.0",
    "rxjs-compat": "^6.1.0",
    "zone.js": "0.8.26"
  },
  "devDependencies": {
    "@angular/cli": "^6.0.1",
    "@angular/compiler-cli": "^6.0.1",
    "@types/fullcalendar": "2.7.40",
    "@types/jasmine": "2.5.38",
    "@types/jquery": "2.0.41",
    "@types/jquery.slimscroll": "1.3.30",
    "@types/lodash": "4.14.61",
    "@types/node": "6.0.69",
    "codelyzer": "3.0.1",
    "gh-pages": "0.12.0",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "3.2.0",
    "karma": "1.4.1",
    "karma-chrome-launcher": "2.0.0",
    "karma-cli": "1.0.1",
    "karma-coverage-istanbul-reporter": "0.2.0",
    "karma-jasmine": "1.1.0",
    "karma-jasmine-html-reporter": "0.2.2",
    "npm-run-all": "4.0.2",
    "protractor": "5.1.0",
    "rimraf": "2.6.1",
    "standard-changelog": "1.0.1",
    "stylelint": "7.10.1",
    "ts-node": "2.1.2",
    "tslint": "5.2.0",
    "tslint-eslint-rules": "4.0.0",
    "tslint-language-service": "0.9.6",
    "typescript": "^2.7.2",
    "typogr": "0.6.6",
    "underscore": "1.8.3",
    "wintersmith": "2.2.5",
    "wintersmith-sassy": "1.1.0"
  }

和我的angular.json:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ng2-admin": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "architect": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "tsConfig": "src/tsconfig.app.json",
            "polyfills": "src/polyfills.ts",
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ],
            "styles": [
              "node_modules/roboto-fontface/css/roboto/sass/roboto-fontface.scss",
              "node_modules/normalize.css/normalize.css",
              "node_modules/font-awesome/scss/font-awesome.scss",
              "node_modules/ionicons/scss/ionicons.scss",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "node_modules/leaflet/dist/leaflet.css",
              "node_modules/chartist/dist/chartist.css",
              "node_modules/fullcalendar/dist/fullcalendar.css",
              "node_modules/handsontable/dist/handsontable.full.css",
              "node_modules/ng2-slim-loading-bar/style.css",
              "src/app/theme/theme.scss",
              "src/styles.scss"
            ],
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/easy-pie-chart/dist/jquery.easypiechart.js",
              "node_modules/jquery-slimscroll/jquery.slimscroll.js",
              "node_modules/tether/dist/js/tether.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/handsontable/dist/handsontable.full.js",
              "node_modules/chroma-js/chroma.js"
            ]
          },
          "configurations": {
            "production": {
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              "aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              "buildOptimizer": true,
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ]
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ng2-admin:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ng2-admin:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ng2-admin:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "karmaConfig": "./karma.conf.js",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "scripts": [
              "node_modules/jquery/dist/jquery.js",
              "node_modules/easy-pie-chart/dist/jquery.easypiechart.js",
              "node_modules/jquery-slimscroll/jquery.slimscroll.js",
              "node_modules/tether/dist/js/tether.js",
              "node_modules/bootstrap/dist/js/bootstrap.js",
              "node_modules/handsontable/dist/handsontable.full.js",
              "node_modules/chroma-js/chroma.js"
            ],
            "styles": [
              "node_modules/roboto-fontface/css/roboto/sass/roboto-fontface.scss",
              "node_modules/normalize.css/normalize.css",
              "node_modules/font-awesome/scss/font-awesome.scss",
              "node_modules/ionicons/scss/ionicons.scss",
              "node_modules/bootstrap/scss/bootstrap.scss",
              "node_modules/leaflet/dist/leaflet.css",
              "node_modules/chartist/dist/chartist.css",
              "node_modules/fullcalendar/dist/fullcalendar.css",
              "node_modules/handsontable/dist/handsontable.full.css",
              "node_modules/ng2-slim-loading-bar/style.css",
              "src/app/theme/theme.scss",
              "src/styles.scss"
            ],
            "assets": [
              "src/assets",
              "src/favicon.ico"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": []
          }
        }
      }
    },
    "ng2-admin-e2e": {
      "root": "",
      "sourceRoot": "",
      "projectType": "application",
      "architect": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "./protractor.conf.js",
            "devServerTarget": "ng2-admin:serve"
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "e2e/tsconfig.e2e.json"
            ],
            "exclude": []
          }
        }
      }
    }
  },
  "defaultProject": "ng2-admin",
  "schematics": {
    "@schematics/angular:component": {
      "prefix": "app",
      "styleext": "scss"
    },
    "@schematics/angular:directive": {
      "prefix": "app"
    }
  }
}

对于Angular 8,只需安装NCU npm软件包[$ npm i -g npm-check-updates]并在此处更新所有检查以获取更多信息freakyjolly.com/how-to-update-local-angular-cli-version
代码间谍

Answers:


730

安装@angular-devkit/build-angular为开发依赖项。此软件包是Angular 6.0中新引入的

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

要么,

yarn add @angular-devkit/build-angular --dev


11
我面临着同样的问题。不幸的是,您的解决方案对我不起作用。你有什么其他的建议?
达到su​​bzerodeluxe

完全一样的错误?和配置文件?他们和这个问题一样吗?
里特威克·戴

是。好吧,我在这个问题上做了更多的探索。事实证明,它在Mac Mini上可以正常工作,因此它可能与Windows上的Node安装有关。
subzerodeluxe

2
升级到角度7-可接受的答案已修复错误(已投票),但并未整体解决升级问题。这确实stackoverflow.com/a/51592138/852806
HockeyJ '18

3
谢谢你 我在尝试遵循Angular教程时遇到了这个问题:angular.io/guide/quickstart-好像有人忘了更新文档?
丹·金

167
npm update

它像魅力一样运作。


3
我在英雄角教程的一半途中移到了新机器上,并从源代码管理中提取了半烘焙的工作。这样就解决了。
Heliac '18年

在我的同事的项目中创建一个分支后,我得到了错误消息。这样就解决了。谢谢。
莫妮

没有检查node modules文件夹中没有“半生半熟”的东西。这只是基于package.json重建节点模块。签出新解决方案时,这是完全正常的事情。
利亚姆

2
它解决所有依赖关系:)。+1
Hammad Sajid

可能还有其他过时的软件包。运行ng update --all以尝试同时更新所有内容。
寂寞

86

适用于角度6及以上

对我来说,有效的解决方案是

npm install

ng update

最后

npm update


当我执行ng更新时,我收到了一些有关所需的几个特定更新的消息。命名要更新的版本命令--------------------------------------------- ----------------------------------- @ angular / core 4.4.7-> 8.2.4 ng更新@角/核心@ ngrx /商店2.2.3-> 8.3.0 ng更新@ ngrx /商店rxjs 5.5.12-> 6.5.3 ng更新rxjs
Aggie Jon

3
感谢@ user9964622,此解决方案为我工作。

@Deep我很高兴能为您提供帮助,编码愉快
The Dead Man


15

如果以下命令不起作用,

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

然后移至项目文件夹并运行以下命令:

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

npm install --save @ angular-devkit / build-angular为我工作,但唯一的问题是我试图从不是以管理员身份运行的命令提示符下运行此命令,而我进入执行该命令却未显示任何错误什么都没有,只有光标处于等待状态,然后我简单地运行了一个带有admin的cmd。谢谢
asifaftab87 '19

14

以上所有答案都是正确的,但对我没有用。我能够进行这项工作的唯一方法是遵循以下步骤/命令:

npm uninstall -g @angular/cli@6.0.8
npm cache clean --force
npm install -g @angular/cli@latest
npm install node-sass -g
ng new MY_PROJECT_NAME
cp -r from_my_old_project to_new_MY_PROJECT_NAME

如果要构建库,请使用ng new MY_PROJECT_NAME --create-application=false倒数第二个命令。我在尝试构建库时遇到此错误。该--create-application=false标志避免引入不必要的依赖关系。(angular.io/guide/creating-libraries#getting-started
VSO

1
在清除npm缓存并重新安装后为我工作
-Braj

9

对于Angular 8

安装npm-check-updates软件包

跑:

$ npm i npm-check-updates
$ ncu -u
$ npm install

该软件包将更新所有软件包并解决此问题

注意:更新后如果遇到此问题:

Angular编译器中的错误需要TypeScript> = 3.4.0和<3.6.0,但是找到了3.6.3。

然后运行:

$ npm install typescript@3.5.3

链接


无法将“ ncu”识别为内部或外部命令,可操作程序或批处理文件。
VivekDev

8

npm install 只需键入npm install并运行,然后项目将无错误运行。或者你可以使用npm install --save-dev @angular-devkit/build-angular


8

以下对我有用。不幸的是,没有其他事情。

npm uninstall @angular-devkit/build-angular
npm install @angular-devkit/build-angular
ng update --all --allow-dirty --force

我收到一条消息,说---allow-dirty未安装。但是更新了我的东西。
Garth Baker

6

试试这个。

npm install

npm update

if it's shows something like this. 

运行npm audit fix修复它们,或npm audit获取详细信息

去做!


1
当您这样做时,NPM会说:“我当然希望您知道自己在做什么。” 那给了我怪胎。
ΕГИІИО

1
由于它有所帮助,因此予以支持-尽管只是部分支持。完成此操作后,我仍然有一些缺少的对等项依赖关系,我会按照以下想法进行安装:stackoverflow.com/a/51063840/2995907
dingalapadum

6

以下命令有效:

npm install
ng update

-您可能会看到消息“我们分析了您的package.json,一切似乎都井然有序。辛苦了!”

npm update

然后尝试开发

ng build 

我收到类型脚本错误,降级为

npm install typescript@">=3.1.1 <3.2

ng build --prod 

产品构建成功。

以下是工作组合

ng --version

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.11.0
@angular-devkit/build-angular     0.11.0
@angular-devkit/build-optimizer   0.11.0
@angular-devkit/build-webpack     0.11.0
@angular-devkit/core              7.1.0
@angular-devkit/schematics        7.1.0
@angular/cli                      7.1.0
@ngtools/webpack                  7.1.0
@schematics/angular               7.1.0
@schematics/update                0.11.0
rxjs                              6.3.3
typescript                        3.1.6
webpack                           4.23.1

5

我在上面进行了所有尝试,这是固定的方法:

->删除node_modules文件夹。

->终端-> npm安装。

希望这对您有所帮助!



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

为我解决了。


4

只需执行以下命令即可解决错误

  • ng update @angular/cli @angular/core
  • npm uninstall @angular-devkit/build-angular
  • npm install --save-dev @angular-devkit/build-angular

    如果以上命令无法解决此错误,请更新节点版本

    • npm更新npm -g

4

首先删除node_modules文件夹

然后重启系统

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

npm install


3

当我们运行诸如之类的命令时ng serve,它使用@ angular / cli的本地版本。因此,首先在本地安装@ angular / cli的最新版本(不带-g标志)。然后使用ng update @angular/cli命令更新cli 。我认为这应该可以解决问题。谢谢

如果您要更新角度项目https://update.angular.io/,此链接可能会为您提供帮助


3

一分钟前,我遇到了同样的问题。我的项目是使用angular-cli 1.6.0版生成的。

1. npm update -g @angular/cli

2. editing my package.json changing the line
    "@angular/cli": "1.6.0",
      to
    "@angular/cli": "^1.6.0",

3. npm update

希望我的帮助有效effective


1
这与找不到模块无关。这仅表示将对任何版本的1.6.x更新cli cli模块
SanSolo


3

这对我有用,提交然后:

ng update @angular/cli @angular/core
npm install --save-dev @angular/cli@latest

3

在将节点从v9升级到v10之后,今天我遇到了同样的问题。
我的环境由docker设置,我不得不从DockerFile中删除以下命令:

npm link @angular/cli

它创建一个符号链接到安装节点的目录。
我猜其中的angular/cli模块与我项目的node_modules目录中的模块版本不同,这会导致问题。




0

@angular-devkit/build-angular在您的开发依赖项下添加,它将起作用,或者您也可以执行

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


0

删除package-lock.json并再次执行npm安装。它应该解决此问题。

**当您使用ng new创建了Angular 6应用程序并且安装了其他依赖项后,您会发现此错误,此修复更合适。


0

就我而言,问题是由于缺少依赖关系。为什么缺少依赖项,因为我忘记了打电话:

npm安装

调用上述命令后,所有必需的依赖项都将加载到node_modules中,这不再是问题



0
  • 删除node_modules。
  • 使用'npm cache clean --verify'清除缓存。
  • 然后再次安装npm。

对我来说就像一个魅力。


0

尝试这个。对我有用

npm uninstall -g @angular/cli
npm cache verify
npm install -g @angular/cli@next

@next将给您beta
Brent

0

不幸的是,所提供的解决方案都不适合我,但grepit的回答启发了我执行以下步骤。我通过操作系统(Windows 10)卸载了node.js,然后再次安装了它。然后安装了Angular CLI。然后创建一个新项目,并将我旧项目的src文件复制到这个新文件中,错误消失了。

以下是说明:

  1. 通过操作系统卸载node.js并重新安装
  2. npm install -g @angular/cli
  3. 将您的项目重命名为YOUR_PROJECT_NAME.old
  4. ng new YOUR_PROJECT_NAME
  5. 运行此hello world项目(ng serve),以确保您不会收到该错误。
  6. xcopy YOUR_PROJECT_NAME.old\src\*.* YOUR_PROJECT_NAME\src /s
    这是Windows版本的副本,请根据您自己的操作系统进行更改。
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.