我正在尝试使用webpack-dev-server运行一个简单的程序,但出现此错误:
module.js:471 throw err; ^ Error: Cannot find module 'webpack' at Function.Module._resolveFilename (module.js:469:15) at Function.Module._load (module.js:417:25) at Module.require (module.js:497:17) at require (internal/module.js:20:19) at Object.<anonymous> at Module._compile (module.js:570:32) at Object.Module._extensions..js (module.js:579:10) at Module.load (module.js:487:32) at tryModuleLoad (module.js:446:12) at Function.Module._load (module.js:438:3)
我已经使用以下npm命令安装了webpack
npm install --save-dev webpack
并且我有以下配置:
(webpack.config.js) var webpack = require('webpack'); var path = require('path'); var BUILD_DIR = path.resolve(__dirname, 'client/public'); var APP_DIR = path.resolve(__dirname, 'client/app'); var config = { entery: APP_DIR + '/index.js', output: { path: BUILD_DIR, filename: 'bundle,js', }, module: { loaders: [ { test: /.jsx?$/, loader: 'babel-loader', exclude: /node_modules/, query: { presets: ['es2015', 'react'] } } ] } }; module.exports = config;
我已经尝试了一切,但我真的迷路了。有人有什么主意吗?
npm install --save-dev webpack 是不足够的。
您还必须安装以下内容:
npm install --save-dev webpack-dev-server
另外,您还可以安装:
npm install --save-dev webpack-dev-middleware webpack-hot-middleware