14

WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment. ERROR in multi ./src/index.js ./dist/bundle.js

look4me
  • 141
  • 1
  • 1
  • 3
  • Version: webpack 4.0.1 WARNING in configuration The 'mode' option has not been set. Set 'mode' option to 'development' or 'production' to enable defaults for this environment. ERROR in multi ./src/index.js ./dist/bundle.js Module not found: Error: Can't resolve './dist/bundle.js' in '/MyDisk/Work/mywork/webServer/documents/webpack-demo' @ multi ./src/index.js ./dist/bundle.js – look4me Feb 27 '18 at 10:28
  • Your question is too broad, I suspect this has to do with the fairly new release of `webpack v4`. Check their documentation on how to migrate to `webpack v4`. – Ru Chern Chong Feb 28 '18 at 11:38

3 Answers3

40

The following is the help message from webpack by typing webpack --help in webpack 4

Usage without config file: webpack <entry> [<entry>] --output [-o] <output>

Notice: --output need to be specified explicitly


Solution:

webpack src/index.js --output dist/bundle.js --mode development

And if you are using webpack.config.js :

const path = require('path');

module.exports = {
  mode: 'development',     // set mode option, 'development' or 'production'
  entry: './src/index.js',
  output: {
    path: path.resolve(__dirname,'dist'),
    filename: "bundle.js"
  }
};
Neven.Leung
  • 820
  • 6
  • 12
1

I am not sure WHAT is the exact question here, but I also had this warnings and solved them by setting the mode property in the Webpack configuration file

package.json

    {
      "name": "my-awesome-project",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "build": "NODE_ENV=production webpack",
      },
      ...
      "devDependencies": {
       ...
      },
      "dependencies": {
       ...
      }
    }

webpack.config.js

const path = require('path');
const HtmlWebPackPlugin = require('html-webpack-plugin');

const distDir = path.join(__dirname, 'dist');

const config = {
  mode: 'development',
  entry: ['./src/js/app.js'],
  output: {
    path: distDir,
    filename: 'js/[name].js',
  },
  module: {
    rules: [
      ...
    ]
  },
  plugins: [
    ...
  ],
  devtool: "eval-source-map", // Default development sourcemap
};

// Check if build is running in production mode, then change the sourcemap type
if (process.env.NODE_ENV === 'production') {
  config.devtool = ''; // No sourcemap for production
  config.mode = 'production';

  // Add more configuration for production here like
  // Uglify plugin
  // Offline plugin
  // Etc,
}

module.exports = config;

Hope it helps.

karlitos
  • 1,604
  • 3
  • 27
  • 59
0

Setting mode in config file sometimes doesnt work. Just adding --mode=development gets it right.

"scripts": {
  "start": "webpack --config webpack.config.js --hot --mode=development",
}
Orar
  • 940
  • 1
  • 10
  • 13