Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error while running react application

Error:

Cannot find module 'webpack/schemas/WebpackOptions.json'

My webpack.config.js looks like this -

var config = {
entry: './main.js',
output: {
    path: '/',
    filename: 'index.js',
},
devServer: {
    inline: true,
    port: 8080
},
module: {
    loaders: [
        {
            test: /\.json$/,
            loader: 'json'
        },
        {
            test: /\.jsx?$/,
            exclude: /node_modules/,
            loader: 'babel-loader',
            query: {
                presets: ['es2015', 'react']
            }
        }
    ]
    }
}
module.exports = config;
like image 438
Bharat Bittu Avatar asked Apr 23 '18 06:04

Bharat Bittu


2 Answers

Sorry to revive this but I had a different solution..

I had used

npm install -g webpack-cli
npm install webpack

The issue seems to happen for me because the CLI is expecting webpack to be installed globally as well? To fix this I instead installed both CLI and webpack locally

npm uninstall -g webpack-cli
npm install webpack webpack-cli

In my package.json I just added:

"scripts": {
  "build": "./node_modules/.bin/webpack-cli",
  "watch": "./node_modules/.bin/webpack-cli --watch",
}

Then whenever I need to use webpack I just use npm run build or npm run watch.

And boom everything magically worked!

This is an issue with Webpack though I believe. I will be reporting it and I'll try to update this answer with it's progress.

UPDATE (2018/05/11): I have reported the issue to the Webpack team on a task I believe may be related. Follow/contribute here: https://github.com/webpack/webpack-cli/issues/299#issuecomment-388390143

UPDATE (2018/05/23): There is apparently a fix now and the issue should be resolved in the next version of webpack-cli. As of this writing though it seems to still not be resolved yet in the public release version of webpack-cli.

like image 69
Barak Gall Avatar answered Oct 04 '22 21:10

Barak Gall


Here's what worked for me:

npm uninstall -g webpack
npm install webpack

Then create a script in your package.json:

  "scripts": {
    "build": "webpack",
  },

Then run npm run build instead of running webpack directly.

like image 34
Snowman Avatar answered Oct 04 '22 20:10

Snowman