ng serve:找不到模块“@angular-devkit/build-angular”。

28 浏览
0 Comments

ng serve:找不到模块“@angular-devkit/build-angular”。

这个问题已经有答案了

Angular 6 - 找不到模块 \"@angular-devkit/build-angular\"

我知道这个问题已经有答案,但是没有一个答案可以解决我的问题,我仍然得到了这个错误的堆栈:

Could not find module "@angular-devkit/build-angular" from "F:\\Documents\\...".
Error: Could not find module "@angular-devkit/build-angular" from "F:\\Documents\\...".
    at Object.resolve (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\core\node\resolve.js:141:11)
    at Observable.rxjs_1.Observable [as _subscribe] (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\@angular-devkit\architect\src\architect.js:132:40)
    at Observable._trySubscribe (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:44:25)
    at Observable.subscribe (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:30:22)
    at C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:99:19
    at new Promise ()
    at Observable.toPromise (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\node_modules\rxjs\internal\Observable.js:97:16)
    at ServeCommand.initialize (C:\Users\...\AppData\Roaming\npm\node_modules\@angular\cli\models\architect-command.js:130:86)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (internal/modules/cjs/loader.js:745:11)

我的全局npm依赖项在C:,但我的项目文件夹和项目依赖项在F:

我尝试过:

  • 使用npm在本地和全局安装模块
  • 删除package-lock,本地node_modules,全局node_modules和npm-cache
  • 卸载再安装node
  • 使用ng new生成一个新应用程序,然后使用npm start/ng serve启动它产生了相同的错误

这是我的package.json:

{
  "name": "...",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "prod": "ng build --prod"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~7.1.0",
    "@angular/cdk": "^7.2.1",
    "@angular/common": "~7.1.0",
    "@angular/compiler": "~7.1.0",
    "@angular/core": "~7.1.0",
    "@angular/flex-layout": "^7.0.0-beta.23",
    "@angular/forms": "~7.1.0",
    "@angular/platform-browser": "~7.1.0",
    "@angular/platform-browser-dynamic": "~7.1.0",
    "@angular/router": "~7.1.0",
    "core-js": "^2.6.2",
    "moment": "^2.23.0",
    "ngx-moment": "^3.3.0",
    "rxjs": "^6.3.3",
    "rxjs-compat": "^6.3.3",
    "tslib": "^1.9.0",
    "zone.js": "^0.8.27"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.12.1",
    "@angular-devkit/core": "^7.2.1",
    "@angular/cli": "~7.2.1",
    "@angular/compiler-cli": "~7.1.0",
    "@angular/language-service": "~7.1.0",
    "@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": "~3.1.1",
    "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.1.6"
  }
}

admin 更改状态以发布 2023年5月21日
0
0 Comments

首先运行以下命令 -

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

如果上述命令不起作用, 那么进入项目文件夹并运行以下命令:

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

如果再次执行ng serve而它仍然无法工作, 那么只需通过以下命令安装npm

npm install

现在运行您的项目, 它将工作.

0
0 Comments

问题是您的angular项目无法找到构建项目所需的"@angular-devkit/build-angular"依赖项。您的堆栈跟踪中的这一部分表明了这一点:

无法从"F:\ Documents \ ..."找到模块"@angular-devkit / build-angular"。

对于Windows,用户计算机上的F:驱动器是次要存储设备,而用户的主存储驱动器是C:驱动器。

我怀疑,由于您正在使用辅助存储来存储项目依赖项,丢失依赖项的原因可能是在C驱动器上错误安装了项目所需的node_modules。也许由于某种原因,该模块已从F驱动器中意外删除。无论您使用npm / yarn还是其他包管理器,都应该能够通过从F驱动器中的项目根目录下载@angular-devkit/build-angular依赖项来解决此错误。以下是一些示例:

cd  
npm i --save-dev @angular-devkit/build-angular

angular-cli会尝试相对于当前目录查找项目所需的node_modules。在尝试构建/服务您的Angular项目时,请牢记这一点。无论您使用哪种包管理器,您都需要安装您项目所需的所有必要依赖项。

希望这有所帮助!

0