【问题标题】:ng build and ng serve not working due to "Could not find the implementation for builder"由于“找不到构建器的实现”,ng build 和 ng serve 无法正常工作
【发布时间】:2019-10-15 09:07:52
【问题描述】:

我正在尝试在我的 Mac 上从 github 运行一个项目。

当我在终端中的正确文件夹中的npm install 之后运行 ng serve 或 ng build 时,我收到以下错误

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 (/Users/x/x/x/Angular/node_modules/@angular/cli/node_modules/@angular-devkit/architect/node/node-modules-architect-host.js:49:19) at ServeCommand.initialize (/Users/sydney/Downloads/HealthLock-Webapp-master/Angular/node_modules/@angular/cli/models/architect-command.js:135:55) at async ServeCommand.validateAndRun (/Users/sydney/Downloads/HealthLock-Webapp-master/Angular/node_modules/@angular/cli/models/command.js:127:9) at async Object.runCommand (/Users/x/x/x/Angular/node_modules/@angular/cli/models/command-runner.js:178:24) at async default_1 (/Users/x/x/x/Angular/node_modules/@angular/cli/lib/cli/index.js:32:31)

我已根据其他时间在此处和其他网站上提出此问题的时间跟踪了我能找到的所有信息。我已卸载并重新安装。我已经清除了缓存。我试过npm install --save-dev @angular-devkit/build-angular、npm update、npm i --only=dev、ng update。我已经尝试了所有我能找到的解决方案,但都没有奏效。

这是我的版本:

 Angular CLI: 8.0.0

 Node: 12.3.1

 OS: darwin x64

 Angular: 8.0.0

 @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.0

 @angular/cdk: 7.3.7

 @angular/http: 8.0.0-beta.10

 @ngtools/webpack: 7.3.9

 @schematics/angular: 8.0.0

 @schematics/update: 0.800.0

 rxjs: 6.5.2

 typescript: 3.4.5

 webpack:4.29.0

这是我的 json 文件

 {
   "name": "x",
   "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.0",
     "@angular/cdk": "^7.3.7",
     "@angular/common": "^8.0.0",
     "@angular/compiler": "^8.0.0",
     "@angular/core": "^8.0.0",
     "@angular/forms": "^8.0.0",
     "@angular/http": "^8.0.0-beta.10",
     "@angular/platform-browser": "^8.0.0",
     "@angular/platform-browser-dynamic": "^8.0.0",
     "@angular/router": "^8.0.0",
     "@types/moment": "^2.13.0",
     "angular2-signaturepad": "^2.8.0",
     "core-js": "^2.6.9",
     "hammerjs": "^2.0.8",
     "html2canvas": "^1.0.0-rc.2",
     "jspdf": "^1.5.3",
     "lodash": "^4.17.11",
     "moment": "^2.24.0",
     "ng-circle-progress": "^1.4.1",
     "ng-select": "^1.0.1",
     "ngx-bootstrap": "^3.3.0",
     "ngx-device-detector": "^1.3.5",
     "ngx-mask": "^6.5.18",
     "ngx-owl-carousel-o": "^0.1.2",
     "rxjs": "6.5.2",
     "rxjs-compat": "6.3.3",
     "zone.js": "^0.9.1"
        },
        "devDependencies": {
          "@angular-devkit/build-angular": "^0.13.9",
          "@angular/cli": "^8.0.0",
          "@angular/compiler-cli": "^8.0.0",
          "@angular/language-service": "^8.0.0",
          "@types/jasmine": "^2.8.16",
          "@types/jasminewd2": "^2.0.6",
         "@types/lodash": "^4.14.132",
          "@types/node": "~8.9.4",
          "codelyzer": "~4.2.1",
     "jasmine-core": "~2.99.1",
     "jasmine-spec-reporter": "~4.2.1",
     "karma": "^4.1.0",
     "karma-chrome-launcher": "~2.2.0",
     "karma-coverage-istanbul-reporter": "^2.0.5",
     "karma-jasmine": "~1.1.1",
     "karma-jasmine-html-reporter": "^0.2.2",
     "protractor": "^5.4.2",
     "ts-node": "~5.0.1",
     "tslint": "~5.9.1",
     "typescript": "^3.4.5"
   }
 }

Angular.json 文件

 {
    "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
    "version": 1,
   "newProjectRoot": "projects",
    "projects": {
     "healthlock": {
     "root": "",
  "sourceRoot": "src",
  "projectType": "application",
  "prefix": "app",
  "schematics": {
    "@schematics/angular:component": {
      "styleext": "scss"
    }
  },
  "architect": {
    "build": {
      "builder": "@angular-devkit/build-angular:browser",
      "options": {
        "outputPath": "dist/healthlock",
        "index": "src/index.html",
        "main": "src/main.ts",
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json",
        "assets": [
          "src/favicon.ico",
          "src/assets"
        ],
        "styles": [
          "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.carousel.min.css",
          "node_modules/ngx-owl-carousel-o/lib/styles/prebuilt-themes/owl.theme.default.min.css",
          "src/styles.scss"
        ],
        "scripts": ["src/env.js"]
      },
      "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": "healthlock:build"
      },
      "configurations": {
        "production": {
          "browserTarget": "healthlock:build:production"
        }
      }
    },
    "extract-i18n": {
      "builder": "@angular-devkit/build-angular:extract-i18n",
      "options": {
        "browserTarget": "healthlock: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.scss"
        ],
        "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/**"
        ]
      }
    }
  }
},
"healthlock-e2e": {
  "root": "e2e/",
  "projectType": "application",
  "architect": {
    "e2e": {
      "builder": "@angular-devkit/build-angular:protractor",
      "options": {
        "protractorConfig": "e2e/protractor.conf.js",
        "devServerTarget": "healthlock:serve"
      },
      "configurations": {
        "production": {
          "devServerTarget": "healthlock:serve:production"
        }
      }
    },
    "lint": {
      "builder": "@angular-devkit/build-angular:tslint",
      "options": {
        "tsConfig": "e2e/tsconfig.e2e.json",
        "exclude": [
          "**/node_modules/**"
        ]
      }
    }
  }
}
    },
   "defaultProject": "healthlock"

【问题讨论】:

  • 你跑ng update了吗?
  • 是的,我在问题中提到过

标签: javascript angular terminal


【解决方案1】:

你可以试试:

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

看起来您正在使用旧的构建器。在版本 8 中,我们更新了 CLI 的一些内部结构。

【讨论】:

    【解决方案2】:

    我在几个项目中遇到了同样的问题。我跑了npm i --save-dev @angular-devkit/build-angular@latest,这似乎为我解决了所有问题。

    注意 - 我的命令末尾有@latest,它将安装最新版本。在我发布此答案时,它安装了版本“0.800.3”。

    希望对你有帮助!

    【讨论】:

    【解决方案3】:

    看起来像@angular/cli@8 的最新版本存在问题;这个issue 可能是相关的。我建议暂时降级到@angular/cli@7。

    【讨论】:

    • 我有 Angular CLI: 7.3.9 和 Node: 12.3.1 并且错误信息是一样的
    【解决方案4】:

    能否分享您的文件:angular.json

    架构师内部应该有这样的东西:{..}

    为 ng 服务:

    ...    
    "serve": {
                  "builder": "@angular-devkit/build-angular:dev-server",
                  "options": {
                    "browserTarget": "HealthLock-Webapp-master:build"
                  },
                  "configurations": {
                    "production": {
                      "browserTarget": "HealthLock-Webapp-master:build:production"
                    }
                  }
                }, ...
    

    对于 ng 构建:

    ...
    "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": [
                  "src/styles.scss",
                  "src/theme.scss"
                ],
                "scripts": []
              },
              "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"
                    }
                  ]
                }}...
    

    【讨论】:

    • 我添加了我的 angular.json
    • 文件看起来正确!不知道你之前有没有试过: 1- delete nodes_modules 2- npm install 3- ng update @angular/cli @angular/core
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-10-30
    • 1970-01-01
    • 1970-01-01
    • 2018-06-10
    • 2014-04-27
    • 1970-01-01
    • 2018-04-19
    相关资源
    最近更新 更多