Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server not working Cannot find module '../lib/polyfills'

I moved my project to another computer, ran npm install. Project works fine except webpack-dev-server, it throws error

module.js:544
throw err;
^

Error: Cannot find module '../lib/polyfills'
    at Function.Module._resolveFilename (module.js:542:15)
    at Function.Module._load (module.js:472:25)
    at Module.require (module.js:585:17)
    at require (internal/module.js:11:18)
    at Object.<anonymous> (/project/node_modules/.bin/webpack-dev-server:6:1)
    at Module._compile (module.js:641:30)
    at Object.Module._extensions..js (module.js:652:10)
    at Module.load (module.js:560:32)
    at tryModuleLoad (module.js:503:12)
    at Function.Module._load (module.js:495:3)

What is it missing ?

like image 517
Alexey K Avatar asked Nov 04 '17 21:11

Alexey K


2 Answers

The fix: rm -rf node_modules && npm install

Because..... who knows why /shrug

like image 148
Kabir Sarin Avatar answered Oct 15 '22 12:10

Kabir Sarin


I had this exact issue and fixed it doing the following.

Running webpack-dev-server gave the error you pasted.

I thought it may have been a configuration issue, so I tried node_modules/.bin/webpack-dev-server to fix the configuration via the CLI.

Doing this, I was given the same error.

The file inside of .bin existed but something was clearly wrong. I suspect it's because I seeded this project by copying from another one and perhaps references normally set as part of npm install weren't set on the copy, so they were still pointing to the source of my copy.

Regardless, run npm install --save-dev webpack-dev-server again and try. Fixed my issue both in running webpack-dev-server and the CLI even though they were already installed. Perhaps just installed improperly.

like image 19
oooyaya Avatar answered Oct 15 '22 14:10

oooyaya