Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

webpack-dev-server Cannot find module 'webpack'

I'm trying to use webpack-dev-server to run a simple program but I'm getting this error:

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) 

I have installed webpack with following npm command

npm install --save-dev webpack 

and I have the following configuration:

(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; 

I have tried everything and I'm really lost. Does anyone have any idea?

like image 532
yonBav Avatar asked Feb 15 '17 17:02

yonBav


People also ask

Can not find module Webpack dev server?

To solve the error "Cannot find module 'webpack/bin/config-yargs'", make sure you're running a recent version of webpack and replace the webpack-dev-server command with webpack serve in your package. json file.

Can not find webpack?

If you're still getting the "Cannot find module 'webpack'" error, open your package. json file and make sure it contains the webpack package in the devDependencies object. Copied! You can try to manually add the line and re-run npm install .

Where is my webpack config JS?

The webpack configuration file webpack. config. js is the file that contains all the configuration, plugins, loaders, etc. to build the JavaScript part of the NativeScript application. The file is located at the root of the NativeScript application.


2 Answers

npm install --save-dev webpack is not enough.

You also have to install the following:

npm install --save-dev webpack-dev-server  

And optionally, you can also install:

npm install --save-dev webpack-dev-middleware webpack-hot-middleware 
like image 90
Abdennour TOUMI Avatar answered Sep 18 '22 12:09

Abdennour TOUMI


I had the same problem, but I resolved by installing additional webpack-cli

npm install --save-dev webpack-cli 
like image 39
Hùng Ng Vi Avatar answered Sep 21 '22 12:09

Hùng Ng Vi