ng build和ng服务无法正常运行,因为“找不到构建器的实现”

时间:2019-05-29 17:38:09

标签: javascript angular terminal

我正在尝试在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-angularnpm updatenpm i --only=devng 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"

4 个答案:

答案 0 :(得分:3)

我在一些项目中遇到过同样的问题。我运行了npm i --save-dev @angular-devkit/build-angular@latest,它似乎可以解决所有问题。

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

希望这对您有帮助!

答案 1 :(得分:0)

能否请您共享文件:angular.json

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

服务:

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

对于ng build:

...
"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"
                }
              ]
            }}...

答案 2 :(得分:0)

@ angular / cli @ 8的最新发行版似乎有问题;该issue可能是相关的。我建议暂时降级为@ angular / cli @ 7。

答案 3 :(得分:0)

您可以尝试:

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

好像您正在使用旧的构建器。在版本8中,我们更新了CLI的某些内部组件。

相关问题