Could not find module ‘@angular-devkit/build-angular’ – How to fix?

Error “Could not find module ‘@angular-devkit/build-angular'”

If you are having difficulties with the problem “Could not find module ‘@angular-devkit/build-angular’” and don’t know how to fix it, let’s read this article. It’s helpful for you.

Cause of this error

In the NPM community, developers shared thousands of libraries with modules that performed a specific function. It helps new projects to avoid rewriting the essential components. “Angular” module is one of them. Maybe your project has not been installed @angular-devkit/build-angular’, so you get the following warning message:

Output:

"Could not find module '@angular-devkit/build-angular'"

How to fix the error “Could not find module ‘@angular-devkit/build-angular'”?

To fix this error, you can use npm to install “build-angular”. Let’s follow these steps to do that:

Step 1: Check your folder project has been installed ‘@angular-devkit/build-angular’

To check for all locally installed ‘@angular-devkit/build-angular’ and their dependencies, navigate to the project folder in your terminal and run ‘npm list’ command.

Below is the ‘@angular-devkit/build-angular’ package installed. If you don’t see it, your project may not have this module installed.

Step 2: Install package module ‘@angular-devkit/build-angular’ 

Normally, “package.json” file will be stored in the root directory. To check and install ‘@angular-devkit/build-angular’ package, you need to go to the root directory to open the terminal and execute the code below:

Terminal/ PowerShell

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

-npm install will directly install your package

– –save-dev will include the third-party package in your project’s dependencies.

@angular-devkit/build-angular is the package you want to install

After you run this command, @angular-devkit/build-angular package will be installed.  

If still error, you can try ‘–unsafe-perm’ flag 

For example:

Terminal/ PowerShell

npm install --save-dev --unsafe-perm <strong>@angular-devkit/build-angular

Sometimes you may encounter a command that does not run because of a permission error. Use sudo to try this command:

Terminal/ PowerShell

sudo npm install --save-dev --unsafe-perm @angular-devkit/build-angular 

‘Unsafe-perm’ flag forces ‘npm’ to download this package binary.

The error may not be resolved, so let’s delete all ‘node_modules’ and ‘package-lock.json’ files and re-install ‘npm install @angular-devkit/build-angular’ and restart VS Code or your IDE. (CAREFUL delete package-lock.json NOT package.json).

If this error still appears, let’s check the ‘package.json’ and make certain @angular-devkit/build-angular module in ‘devDependencies’ has been installed.

Package.json

{
  "devDependencies": {
	"@angular-devkit/build-angular": "^14.2.3",
   }
}

Or try to use the command below to install the newest @angular-devkit/build-angular version:

Terminal/ PowerShell

npm install --save-dev @angular-devkit/[email protected]

@angular-devkit/build-angular will be contained in the “devDependencies” object of the package.json file instead of in your project’s dependencies.

Summary

I hope this post can help you fix this error. The error Could not find module @angular-devkit/build-angular error may occur because your project doesn’t install the @angular-devkit/build-angular package. If you want to learn how to use @angular-devkit/build-angular, this guide will show you how. Happy coding.

Maybe you are interested:

Leave a Reply

Your email address will not be published. Required fields are marked *