Borislav Hadzhiev
Mon Mar 28 2022·2 min read
Photo by Parker Johnson
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:
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
).
{ "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.
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.
# 👇️ 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
If you still get the error, try to update the versions of your NPM packages by running the following command:
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.