"Webpack Dev Server Invalid Options" without good explanation on what fails (have no idea)

See original GitHub issue
  • Operating System: Windows 10
  • Node Version: 10.6.0
  • NPM Version: 6.1.0
  • webpack Version: ^4.18.0
  • webpack-dev-server Version: ^3.1.8
  • [x ] This is a bug
  • This is a modification request

Code

  // webpack.config.js
// require('argv-set-env')();

const webpack = require('webpack');
const path = require('path');
const Clean = require('clean-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const OpenBrowserPlugin = require('open-browser-webpack-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const ExtractTextPlugin = require('extract-text-webpack-plugin');
const merge = require('webpack-merge');
const DashboardPlugin = require('webpack-dashboard/plugin');
const WebpackMd5Hash = require('webpack-md5-hash');

const ROOT_PATH = path.resolve(__dirname);
const TARGET = process.env.TARGET;
const APP = process.env.APP;
const PORT = process.env.PORT;
const MOCK = process.env.MOCK;
const MOBILEWEB = process.env.MOBILEWEB;
const LGPROCENTRIC = process.env.LGPROCENTRIC;
const ENTRY = MOBILEWEB ? 'mainMobileWeb.js' : 'main.js';

const outputPath = MOBILEWEB ? `public/mobileweb/${APP}` : `public/${APP}`;

const common = {
    entry: {
        bundle: [path.resolve(ROOT_PATH, `src/js/${ENTRY}`)]
    },
    resolve: {
        extensions: ['.js']
    },
    output: {
        path: path.resolve(ROOT_PATH, outputPath),
        filename: '[name].[chunkhash].js'
    },
    module: {
        rules: [
            {
                test: /\.css$/,
                use: [
                    {
                        loader: "style-loader"
                    },
                    {
                        loader: "css-loader",
                        /*options: {
                            modules: true
                        }*/
                    }
                ],
                include: [path.resolve(ROOT_PATH, 'src/css'), path.resolve(ROOT_PATH, 'node_modules/react-image-gallery/styles/css')],
            },
            {
                test: /\.s[c|a]ss$/,
                use: ['style-loader', 'css-loader', 'sass-loader'],
                include: [path.resolve(ROOT_PATH, 'src/css')]
            },
            {
                test: /\.js$/,
                include: [path.resolve(ROOT_PATH, 'src')],
                exclude: /smaf\.js/,
                loader: "babel-loader"
            },
            {
                test: /\.(eot|woff|woff2|ttf|svg|png|jpe?g|gif)(\?\S*)?$/,
                include: [path.resolve(ROOT_PATH, 'src')],
                exclude: /smaf\.js/,
                loader: 'url?limit=8192&name=[name].[ext]'
            },
            {
                test: /\.json$/,
                loader: 'json-loader'
            }]
    },
    plugins: [
        // new DashboardPlugin({port: PORT}),
        new ExtractTextPlugin('[name].css'),
        new Clean([outputPath]),
        new CopyWebpackPlugin([
            // {from: 'src/css', to: 'css', force: true},
            {from: 'src/img', to: 'img', force: true}
        ]),
        new HtmlWebpackPlugin({
            title: MOBILEWEB ? 'Test' : 'Test UI',
            description: MOBILEWEB ? 'Test: Get the Most from Life!' : 'The Test Smart TV application',
            template: 'src/base-template.html',
            favicon: 'src/favicon.ico',
            inject: 'body',
            filename: 'index.html'
        }),
        new WebpackMd5Hash(),
    ]
};

if (TARGET === 'start' || !TARGET) {
    let queryParams = '';
    module.exports = merge(common, {
        mode: 'development',
        devtool: 'source-map',
        devServer: {
            contentBase: `./${outputPath}`,
            outputPath: path.resolve(ROOT_PATH, outputPath),
            historyApiFallback: true,
            hot: true,
            host: '0.0.0.0',
            inline: true,
            port: PORT,
            progress: true,
            disableHostCheck: true,
        },
        plugins: [
            new webpack.HotModuleReplacementPlugin(),
            new webpack.DefinePlugin({
                'process.env': {
                    // This has effect on the react lib size PLUS determines the 'APP' to be used
                    // 'NODE_ENV': JSON.stringify('development'),
                    'APP': JSON.stringify(APP),
                    'MOCK': JSON.stringify(MOCK),
                    'MOBILEWEB': JSON.stringify(MOBILEWEB),
                    'LGPROCENTRIC': JSON.stringify(LGPROCENTRIC),
                },
            }),
            new OpenBrowserPlugin({url: `http://localhost:${PORT}/?${queryParams}`})
        ]
    });
}

if (TARGET === 'build') {
    module.exports = merge(common, {
        mode: 'production',
        plugins: [
            new webpack.DefinePlugin({
                'process.env': {
                    // This has effect on the react lib size PLUS determines the 'APP' to be used
                    // 'NODE_ENV': JSON.stringify('production'),
                    'APP': JSON.stringify(APP),
                    'MOBILEWEB': JSON.stringify(MOBILEWEB),
                    'LGPROCENTRIC': JSON.stringify(LGPROCENTRIC),
                },
            }),
        ]
    });
}
  // additional code, remove if not needed.
// PACKAGE.JSON
"scripts": {
    "start-dinings": "cross-env APP=dinings TARGET=start PORT=33102 webpack-dev-server",

Expected Behavior

Webpack-dev-server to start when running npm run start-dinings

It used to start when I was in version 2 of webpack (now upgraded to latest version 4)

Actual Behavior

ERROR:

image

For Bugs; How can we reproduce the behavior?

For Features; What is the motivation and/or use-case for the feature?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

13reactions
Muziettocommented, Sep 24, 2018

In my case, adding outputPath to the dev-server config object just doubled the error message:

options should NOT have additional properties
options should NOT have additional properties

I removed colors: true, (suggested somewhere) and the error message went away. I guess this is all about the version of webpack-dev-server we are using. In my case it’s 3.1.8

3reactions
michael-ciniawskycommented, Sep 12, 2018
        devServer: {
            contentBase: `./${outputPath}`,
-           outputPath: path.resolve(ROOT_PATH, outputPath),
            historyApiFallback: true,
            hot: true,
            host: '0.0.0.0',
            inline: true,
            port: PORT,
            progress: true,
            disableHostCheck: true,
        },

See https://webpack.js.org/configuration/dev-server/ for all available devServer options

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix "webpack Dev Server Invalid Options" in Vuejs
I have no idea why you're getting that error but here is how you'd configure that option: 1. Create vue.config.js in your root...
Read more >
How to fix "webpack Dev Server Invalid Options" in Vuejs-Vue.js
I have no idea why you're getting that error but here is how you'd configure that option: 1. Create vue.config.js in your root...
Read more >
[webpack-cli] webpack dev server invalid options - You.com
Dev Server has been initialized using an options object that does not match the API ... "Webpack Dev Server Invalid Options" without good...
Read more >
Having an issue with webpack config when developing - Plugins
I am having an issue when developing MFEs which is slowing me down a bit. ... 「wds」: webpack Dev Server Invalid Options options....
Read more >
To v5 from v4 - webpack
Upgrade webpack 4 and its plugins/loaders · Make sure your build has no errors or warnings · Make sure to use mode ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found