60

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

Gil Epshtain
  • 8,670
  • 7
  • 63
  • 89
kosnkov
  • 5,609
  • 13
  • 66
  • 107

6 Answers6

129

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.

Gil Epshtain
  • 8,670
  • 7
  • 63
  • 89
Tristan mariën
  • 1,306
  • 1
  • 9
  • 4
43

I fixed this issue with:

delete package-lock.json
delete node_modules
delete dist (if exist)

npm cache clean --force

npm install
Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135
softloft
  • 571
  • 4
  • 4
5

This error mostly occurs because of old dependencies, if at all are not upgraded then it can be deleted manually by deleting the node_modules Folder and also the package-lock.json file

after that you can clean the Cache (if at all necessary) and then

npm cache clean --force
npm install
Onkar Nirhali
  • 216
  • 2
  • 8
5

While using npm link webpack worked locally, on my CI (GitHub actions) I had the same problem, and to resolve it I used:

 npm i --save-dev webpack
Francesco Borzi
  • 56,083
  • 47
  • 179
  • 252
0
npm update --force

solved my problem

-10

Try to see if this works...

npm uninstall --save webpack
npm install --save-dev webpack
vencaslac
  • 2,727
  • 1
  • 18
  • 29
Sehul Viras
  • 587
  • 5
  • 9
  • 11
    Don't ! In latest angular versions the webpack dependency is manager by the CLI and you shouldn't have a webpack entry in your package.json at all. – petronius Sep 09 '19 at 12:29