npm argument results in "Insufficient number of arguments or no entry found"

As @squgeim mentioned, webpack does not support flags and environment variables should be used. This pointed me in the right direction: Environment variables

I changed my package.json and webpack.config.js file like this:

package.json

"scripts": {
    "dev": "webpack --mode development --env.dist=false",
    "dev:dist": "webpack --mode development",
    "build": "webpack --mode production"
},

--env.dist=false adds dist to the environment variables.

webpack.config.js

There is one change that you will have to make to your webpack config. Typically, module.exports points to the configuration object. To use the env variable, you must convert module.exports to a function.

module.exports = env => {
    const no_dist = (env && env.dist === "false");

return {
    //webpack configuration
}

This seems to be the correct way to do it. Thanks again @squgeim to point me in the right direction!


I just got the same error yesturday,and i found out in my case it is due to the ES6 syntax error.I used module.export instead of module.exports in webpack.config.js.