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

偶尔善良 提交于 2019-12-09 14:57:30

问题


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 ?


回答1:


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.




回答2:


The fix: rm -rf node_modules && npm install

Because..... who knows why /shrug



来源:https://stackoverflow.com/questions/47115764/webpack-dev-server-not-working-cannot-find-module-lib-polyfills

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!