I'm just getting started with webpack and am having difficulty getting the multiple-entry-points sample to build. The webpack.config.js file in the example includes the line
var CommonsChunkPlugin = require("../../lib/optimize/CommonsChunkPlugin");
which fails for me with the error
Error: Cannot find module '../../lib/optimize/CommonsChunkPlugin'
Searching around, I found other examples of using the CommonsChunkPlugin with the expression
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin("common.js");
which fails with the error
ReferenceError: webpack is not defined
Some more searching found a number of examples including
var webpack = require('webpack');
and my build now fails with
Error: Cannot find module 'webpack'
I'm at a loss as to how to proceed.
npm install webpack
before?Error: Cannot find module 'webpack'
is a node error. So this has nothing to do with webpack itself (afaict). It seems like node is looking in the wrong folders...npm install -g webpack
didn't work for me either. But it does withnpm install webpack
- make sure you are in the app root folder when you callnpm install webpack
then check if the module exists innode_modules
folder. It also seems thatwebpack
needsfsevents
(optional) module on linux systems - I'm using Windows so I'm not sure - try installingfsevents
alsowebpack
in the local app folder, usingnpm install webpack
, without-g