Solve - Cannot find module '@angular/core' error

avatar

Borislav Hadzhiev

Mon Mar 28 20222 min read

Solve - Cannot find module '@angular/core' error #

To solve the error "Cannot find module '@angular/core'", make sure you have installed all dependencies by running the npm install command, set the baseUrl option to src in your tsconfig.json file and restart your IDE and development server.

Open your terminal in your project's root directory (where your package.json file is located) and run the following command:

shell
npm install

If the error is not resolved, open your main tsconfig file and set the baseUrl option to src. (This could be tsconfig.json or tsconfig.app.json).

tsconfig.json
{ "compilerOptions": { "baseUrl": "src", // ... rest } }

The baseUrl option lets us specify a base directory to resolve non-absolute module names.

With baseUrl set to src, TypeScript will look for files starting at the src folder.

Make sure to restart your IDE and dev server if the error still persists.

If you still get the error, try to delete your node_modules and package-lock.json (not package.json) files, re-run npm install and restart your IDE.

shell
# 👇️ delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json # 👇️ clean npm cache npm cache clean --force npm install
Make sure to restart your IDE and dev server if the error still persists. VSCode often glitches and a reboot solves things sometimes.

If you still get the error, try to update the versions of your NPM packages by running the following command:

shell
npm update

If you use VSCode, make sure to open your code editor in the root directory of your project (where the package.json file is located).

If you open your IDE in a different directory, e.g. one directory up, the "Cannot find module '@angular/core'" error is caused.

Use the search field on my Home Page to filter through my more than 1,000 articles.