Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot find module 'webpack' - Angular

I just migrated my project from angular v5.x to v6.x and now when I try to start it with ng serve I'm getting:

Cannot find module 'webpack' Error: Cannot find module 'webpack'   at Function.Module.... 

any help ?

I cleared node modules and:

  • npm cache clean --force
  • npm install
  • npm install --save-dev @angular/cli@latest

but that didn't help

like image 691
kosnkov Avatar asked Jun 29 '18 07:06

kosnkov


2 Answers

I had the same issue and this worked for me:

  1. Delete these files/ folders (from your Angular root folder):

    • package-lock.json (Not the package.json)
    • /node_modules folder
    • /dist folder
  2. Execute command (regenerate the package-lock.json and the /node_modules):

    • $npm install

Everything should work now, it was the package-lock.json that caused npm to download old versions of dependencies.

like image 185
Tristan mariën Avatar answered Oct 14 '22 01:10

Tristan mariën


I fixed this issue with:

delete package-lock.json delete node_modules delete dist (if exist)  npm cache clean --force  npm install 
like image 26
softloft Avatar answered Oct 14 '22 03:10

softloft