node.js 在 ng serve 命令上找不到 builder @angular-devkit/build-angular:dev-server 的实现

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/56623458/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:57:30  来源:igfitidea点击:

Could not find the implementation for builder @angular-devkit/build-angular:dev-server on ng serve command

node.jsangularnpmecmascript-6single-page-application

提问by user2748531

I tried to update the angular CLI following this, but now I can't run my app. When I try to run the command ng serve, it gives me this error:

我尝试更新下角CLI这个,但现在我不能运行我的应用程序。当我尝试运行命令时ng serve,它给了我这个错误:

Could not find the implementation for builder @angular-devkit/build-angular:dev-server
Error: Could not find the implementation for builder @angular-devkit/build-angular:dev-server
    at WorkspaceNodeModulesArchitectHost.resolveBuilder (C:\Users\Lupus\Documents\full-stack-projects\financial-app-ui\node_modules\@angular\cli\node_modules\@angular-devkit\architect\node\node-modules-architect-host.js:49:19)
    at ServeCommand.initialize (C:\Users\Lupus\Documents\full-stack-projects\financial-app-ui\node_modules\@angular\cli\models\architect-command.js:135:55)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)
    at startup (internal/bootstrap/node.js:283:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

I have tried everything I could found.

我已经尝试了我能找到的一切。

  • I tried to manually install devkit with the command npm install --save-dev @angular-devkit/build-angular
  • I tried to run the command npm i --only=dev
  • I tried to run the commands
  • 我尝试使用以下命令手动安装 devkit npm install --save-dev @angular-devkit/build-angular
  • 我试图运行命令 npm i --only=dev
  • 我试图运行命令

:

npm install
ng update
npm update
  • Removed the node_modulesfolder and the package-lock.jsonfile and ran the commands all again.
  • 删除node_modules文件夹和package-lock.json文件并再次运行所有命令。

Nothing worked. Running ng vgives me this:

没有任何效果。跑步ng v给了我这个:

Angular CLI: 8.0.3
Node: 10.15.0
OS: win32 x64
Angular: 8.0.1
... animations, cdk, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.9
@angular-devkit/build-angular     0.13.9
@angular-devkit/build-optimizer   0.13.9
@angular-devkit/build-webpack     0.13.9
@angular-devkit/core              7.3.9
@angular-devkit/schematics        8.0.3
@angular/cli                      8.0.3
@ngtools/webpack                  7.3.9
@schematics/angular               8.0.3
@schematics/update                0.800.3
rxjs                              6.5.2
typescript                        3.4.5
webpack                           4.29.0

And my package.json is like this:

而我的 package.json 是这样的:

{
  "name": "financial-app-ui",
  "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": "^8.0.1",
    "@angular/cdk": "^8.0.1",
    "@angular/common": "^8.0.1",
    "@angular/compiler": "^8.0.1",
    "@angular/core": "^8.0.1",
    "@angular/forms": "^8.0.1",
    "@angular/platform-browser": "^8.0.1",
    "@angular/platform-browser-dynamic": "^8.0.1",
    "@angular/router": "^8.0.1",
    "core-js": "^2.6.9",
    "font-awesome": "^4.7.0",
    "primeicons": "^1.0.0",
    "primeng": "^7.1.3",
    "rxjs": "~6.5.2",
    "tslib": "^1.10.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.13.9",
    "@angular/cli": "^8.0.3",
    "@angular/compiler-cli": "^8.0.1",
    "@angular/language-service": "^8.0.1",
    "@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": "~4.0.0",
    "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.4.5"
  }
}

Does anyone have any other suggestion?

有没有人有其他建议?

回答by Phillip Ngan

I got this working by reinstalling the build-angular package. Note the '--save-dev' flag on the install command:

我通过重新安装 build-angular 包来解决这个问题。请注意安装命令上的“--save-dev”标志:

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

回答by Pradeep

Resolved my issue by using the below command:

使用以下命令解决了我的问题:

ng update @angular/cli @angular/core --allow-dirty --force

回答by Tony Ngo

Make sure you have this configuration in your angular.json

确保你的 angular.json 中有这个配置

    "serve": {
      "builder": "@angular-devkit/build-angular:dev-server",
      "options": {
        "browserTarget": "angular8:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "angular8:build:production"
        }
      }
    }

And make sure you have installed this package

并确保你已经安装了这个包

@angular-devkit/build-angular

回答by NUKE

I'm having the same issue, but in my case I am trying to serve a downloaded template of an Angular project. At first it gave me this error after a ng serve --openterminal command.

我遇到了同样的问题,但就我而言,我正在尝试提供 Angular 项目的下载模板。起初它在ng serve --open终端命令后给了我这个错误。

An unhandled exception occurred:

发生了未处理的异常:

Could not find module "@angular-devkit/build-angular" from "D:\WORK\Desarrollo\plantillas descargadas\argon-dashboard-angular-master".

无法从“D:\WORK\Desarrollo\plantillas descargadas\argon-dashboard-angular-master”中找到模块“@angular-devkit/build-angular”。

I solved that following this Stack Overflow question: https://stackoverflow.com/a/50333128, but got these warnings:

我解决了这个堆栈溢出问题:https: //stackoverflow.com/a/50333128,但收到了这些警告:

npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN @ngtools/[email protected] requires a peer of @angular/compiler-cli@>=5.0.0 
<8.0.0 || ^7.0.0-beta.0 but none is installed. You must install peer dependencies 
yourself.
npm WARN [email protected] requires a peer of ajv@^6.9.1 but none is installed. You 
must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] 
(node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for 
[email protected]: wanted {"os":"darwin","arch":"any"} (current: 
{"os":"win32","arch":"x64"})

But then I got this error after trying the command:

但是在尝试命令后我收到了这个错误:

ng serve --open

An unhandled exception occurred: Could not find the implementation for builder @angular-devkit/build-angular:dev-server

发生未处理的异常:找不到 builder @angular-devkit/build-angular:dev-server 的实现

I noticed that there were some files missing in my node_modules folder, probably caused by my current connection speed. Anyway I tried on a different computer, somewhere else, opened a clone of the project itself and ran the command:

我注意到 node_modules 文件夹中缺少一些文件,可能是由于我当前的连接速度造成的。无论如何,我尝试在另一台计算机上的其他地方打开项目本身的克隆并运行命令:

npm update

then take the project in a .rar file to my working computer and decompressed it, run my VS Code and it just worked perfectly.

然后将 .rar 文件中的项目带到我的工作计算机并解压缩它,运行我的 VS Code 并且它完美地工作。

回答by kotpal

ng updateshould have updated the version for your @angular-devkit/build-angular

ng update应该已经为您更新了版本 @angular-devkit/build-angular

I ran into this as well and what I did was created a new Angular app and ensured that ng servewas working fine for that newly created Angular app. I then copied and used the following from the working Angular app's package.json, which is:

我也遇到了这个问题,我所做的是创建了一个新的 Angular 应用程序,并确保ng serve它对新创建的 Angular 应用程序运行良好。然后我从正在运行的 Angular 应用程序中复制并使用了以下内容package.json,即:

`"@angular-devkit/build-angular": "~0.802.2",`
`"@angular-devkit/build-angular": "~0.802.2",`

Ensure you run npm install

确保您运行 npm install

(The version would most probably change with each Angular update - so check what version you need to use by following the steps I have outlined - if ng update doesn't already update it for you)

(版本很可能会随着每个 Angular 更新而改变 - 所以按照我概述的步骤检查你需要使用的版本 - 如果 ng update 还没有为你更新它)