When you encounter the error message “package ‘@angular/core’ is not a dependency”, it means that you are trying to import or use a module or package that is not declared as a dependency in your project.
In Angular, dependencies are declared in the package.json
file. The package.json
file lists all the packages and their versions that your project depends on. It also manages the installation, update, and removal of these packages using package managers like npm or yarn.
To resolve this error, you need to add ‘@angular/core’ as a dependency. Here are the steps to do this:
- Open your project’s root directory in your preferred code editor.
- Locate the
package.json
file. - Open the
package.json
file and find the “dependencies” section. - In the “dependencies” section, add the line “
"@angular/core": "^x.x.x"
” (replacex.x.x
with the desired version of Angular Core). - Save the
package.json
file. - Open your terminal or command prompt.
- Navigate to your project’s root directory.
- Run the command “
npm install
” or “yarn install
” to install the Angular Core package.
After following these steps, the “@angular/core” package will be added as a dependency to your project, and you should be able to import and use it without encountering the error. Make sure to replace “x.x.x
” with the desired version of Angular Core that matches the version of Angular you are using in your project.
Here’s an example of how the “dependencies” section in your package.json
file might look after adding “@angular/core” dependency:
"dependencies": {
...
"@angular/core": "^12.2.0",
...
}