简体   繁体   中英

An unhandled exception occurred: Could not find module "@angular-devkit/build-angular"

When running the terminal commands ng server or ng serve I'm getting this issue:

An unhandled exception occurred: Could not find module "@angular-devkit/build-angular"

Check in your package.json to see if you have this package in your devDependencies section or not

"devDependencies": {
    "@angular-devkit/build-angular": "~0.803.18"
}

If exist try to

delete package-lock.json or yarn-lock.json

run

npm cache clean --force

then run

npm i

This error (Unhandled exception for a module) occurs when node_modules folder does not exist inside the project, or when the folder exists, but does not contain all the dependencies downloaded.

$ npm install command will download all the dependencies into the node_modules folder of the proejct.

npm install is automatically triggered in the background by the ' ng new ', at the time of creation of the angular project.

The other angular commands like ' ng build ' or ' ng serve ' commands assume that 'ng new' had completed successfully.

If, for some reason, the npm install failed at the time of creation, or if the node_modules folder got deleted after the project was created, then the other angular commands (ng serve, ng build, ...) will generate this 'Unhandled Exception'.

Manually executing the npm install command inside the project will download the dependencies and fix the issue.

尝试这个

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

Install @angular-devkit/build-angular as dev dependency.

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

or,

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

在你的 angular 根目录中运行 npm install 之前,确保"@angular-devkit/build-angular": "~0.10.0"package.json devDependencies中可用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM