折腾:
【已解决】Webpack打包出错:ERROR in Entry module not found Cannot resolve file or directory
期间,
➜ react-hot-boilerplate git:(master) ✗ webpack –progress –colors –display-error-details zsh: command not found: webpack ➜ react-hot-boilerplate git:(master) ✗ node_modules/webpack/bin/webpack.js -v 3.5.4 ➜ react-hot-boilerplate git:(master) ✗ node_modules/webpack/bin/webpack.js –progress –colors –display-error-details module.js:487 throw err; ^ Error: Cannot find module ‘tapable’ at Function.Module._resolveFilename (module.js:485:15) at Function.Module._load (module.js:437:25) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/Compiler.js:8:17) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/crifan/dev/dev_root/daryun/Projects/xxx/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/webpack.js:7:18) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) |
再去重新全局的安装一下:
➜ react-hot-boilerplate git:(master) ✗ npm install webpack -g /usr/local/bin/webpack -> /usr/local/lib/node_modules/webpack/bin/webpack.js > [email protected] install /usr/local/lib/node_modules/webpack/node_modules/fsevents > node install [fsevents] Success: “/usr/local/lib/node_modules/webpack/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node” already installed Pass –update-binary to reinstall or –build-from-source to recompile > [email protected] postinstall /usr/local/lib/node_modules/webpack/node_modules/uglifyjs-webpack-plugin > node lib/post_install.js added 363 packages in 18.97s |
结果还是:
➜ react-hot-boilerplate git:(master) ✗ webpack –progress –colors –display-error-details module.js:487 throw err; ^ Error: Cannot find module ‘tapable’ at Function.Module._resolveFilename (module.js:485:15) at Function.Module._load (module.js:437:25) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/crifan/dev/dev_root/daryun/Projects/xxxb/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/Compiler.js:8:17) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) at tryModuleLoad (module.js:466:12) at Function.Module._load (module.js:458:3) at Module.require (module.js:513:17) at require (internal/module.js:11:18) at Object.<anonymous> (/Users/crifan/dev/dev_root/daryun/Projects/xxxb/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/webpack/lib/webpack.js:7:18) at Module._compile (module.js:569:30) at Object.Module._extensions..js (module.js:580:10) at Module.load (module.js:503:32) ➜ react-hot-boilerplate git:(master) ✗ webpack -v 3.5.4 ➜ react-hot-boilerplate git:(master) ✗ which webpack /usr/local/bin/webpack |
但是此处去找,是可以找到的:
react-hot-boilerplate/react-hot-boilerplate/package-lock.json
“tapable”: { “version”: “0.2.8”, “resolved”: “http://registry.npm.taobao.org/tapable/download/tapable-0.2.8.tgz”, “integrity”: “sha1-mTcqXJmb8t8WCvwNdL7U9HlIzSI=”, “dev”: true }, |
注意此处的:
package.json是没有依赖tapable的。
对于上述的链接地址:
http://registry.npm.taobao.org/tapable/download/tapable-0.2.8.tgz
也是可以打开和下载的。
webpack Error Cannot find module tapable
Cannot find module ‘tapable’ · Issue #107 · webpack/react-starter
install error Cannot find module ‘tapable’ · Issue #4 · codeinthedark/editor
Error: Cannot find module ‘tapable’ · Issue #423 · AngularClass/angular-starter
Can’t get the boilerplate code to npm-start · Issue #11 · gaearon/react-hot-boilerplate
试试:
npm cache clear –force
rm -rf node_modules
npm install
➜ react-hot-boilerplate git:(master) ✗ npm cache clear –force npm WARN using –force I sure hope you know what you are doing. ➜ react-hot-boilerplate git:(master) ✗ rm -rf node_modules ➜ react-hot-boilerplate git:(master) ✗ npm install > [email protected] install /Users/crifan/dev/dev_root/daryun/Projects/xxxsourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/fsevents > node install [fsevents] Success: “/Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/fsevents/lib/binding/Release/node-v57-darwin-x64/fse.node” already installed Pass –update-binary to reinstall or –build-from-source to recompile > [email protected] postinstall /Users/crifan/dev/dev_root/daryun/Projects/xxx/sourcecode/web/AdminManagement/reference/react-hot-boilerplate/react-hot-boilerplate/node_modules/uglifyjs-webpack-plugin > node lib/post_install.js added 1049 packages in 62.511s |
然后就解决问题了。
【总结】
此处,react-hot-boilerplate中webpack打包出错:
Error Cannot find module tapable
的原因是:
不知道什么时候,本地的npm被破坏了。
所以,在重新安装了wepback 3.x之后,去:
强制清空缓存:npm cache clear –force
删除掉本地的node_modules:rm -rf node_modules
重新安装所有的依赖的库:npm install
之后就可以了。
转载请注明:在路上 » 【已解决】webpack打包出错:Error Cannot find module tapable