15

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;
1
  • which version of webpack-dev-server are you using? got same problem and it's just working with "webpack-dev-server": "2.5.1" for me now. Commented Apr 23, 2018 at 9:26

6 Answers 6

15

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

1

In that case you should need to run in your existing app

yarn install

or

npm install

It may fix your issue.

6 Comments

I did run npm install. I am still facing the same error.
Error - Error: Cannot find module 'webpack/schemas/WebpackOptions.json'
which node version you are using, I am using node v8.9.4. and in node_modules\webpack\schemas path i get webpackOptionsSchema.json file not any WebpackOptions.json.
I am using v8.11.1 node. I don't see schemas under node_modules/webpack.
Try blowing away your entire node_modules folder and running yarn again.
|
1

I resolved this issue by simply adding webpack locally (yarn add --dev webpack). I had it installed globally but when I ran it in the console, gave me this error.

Hope it works for you!

Comments

0

Use the global version of webpack & webpack-cli for now. This affects local installations, as webpack and the cli are split and they can't resolve each other

Comments

0

in windows, run cmd in administrator mode, then

npm install -g  webpack webpack-cli

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.