What will happen if I delete node_modules folder?

Viewed 6714

I'm getting an error after installing any package via npm. Every time I serve my application through ng serve, it gives me an error saying Error: Type [packageName] does not have 'ɵmod' property. What should I do?

I guess if I delete my node_modules folder and re-create it via npm install command, it would be resolved.

Anybody can suggest if I delete node_modules folder and after re-creating it, will I get all the already installed packages back in the same way they were just before deleting?

2 Answers

if i delete node_modules folder and after re-creating it, will i get all the already installed packages back in the same way they were just before?

answer is yes.

or you can do it with

npm ci

its faster and do the same job.

but what if problem is with your package-lock?

your team commited package-lock.json and in merge or somehow its not the correct.

here you need to remove package-lock too.

now getting packages same as they were beforedepends on your package.json.

look at this package.json

{
  "name": "awesome-app",
  "version": "1.0.0",
  "description": "",
  "main": "dist/index.js",
  "scripts": {
   .
   .
   .
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "angular": "^1.8.1"
   },
}

every time i run npm install, because of "^", npm looks for last angular release which match 1.X.X version and update your package to that version.

enter image description here

if we see angular versions on npm website, angular released 1.8.2 one month after 1.8.1 . so this depends on when you are installing and how did you specify version range.

read more about npm flags

Related