【解决】Cannot find module 'webpack'

配置webpack管理React,执行npm start报错

Error: Cannot find module ‘webpack’
at Function.Module._resolveFilename (module.js:326:15)
at Function.Module._load (module.js:277:25)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/home/song/program/react_started/node_modules/webpack-dev-server/bin/webpack-dev-server.js:17:15)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Function.Module.runMain (module.js:442:10)


尝试1

sudo npm install webpack-dev-server -g

改为

sudo npm install webpack-dev-server

其中 -g 参数表示全局安装

尝试2

webpack 作为本地依赖安装

sudo npm i -D webpack

上述操作成功解决问题,两种方法的具体适用情景尚未探究

你可能感兴趣的:(react)