Reputation: 5792
I'm trying to use two configurations with webpack, but it fails in any way that I try, I allways get this message:
TypeError: Cannot read property 'tap' of undefined
In the docs, it says that it is supported, even with an array of functions:
Instead of exporting a single configuration object/function, you may export multiple configurations (multiple functions are supported since webpack 3.1.0). When running webpack, all configurations are built.
I'm using [email protected]
and [email protected]
.
This is the error:
$ webpack --info-verbosity verbose
C:\Users\...\node_modules\webpack-cli\bin\cli.js:281
compiler.hooks.beforeRun.tap("WebpackInfo", compilation => {
^
TypeError: Cannot read property 'tap' of undefined
at processOptions (C:\Users\...\node_modules\webpack-cli\bin\cli.js:281:31)
at yargs.parse (C:\Users\...\node_modules\webpack-cli\bin\cli.js:373:3)
at Object.parse (C:\Users\...\node_modules\yargs\yargs.js:567:18)
at C:\Users\...\node_modules\webpack-cli\bin\cli.js:49:8
at Object.<anonymous> (C:\Users\...\node_modules\webpack-cli\bin\cli.js:375:3)
at Module._compile (internal/modules/cjs/loader.js:701:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:712:10)
at Module.load (internal/modules/cjs/loader.js:600:32)
...
And this is my code (full code here):
// @ts-check
const webpack = require('webpack');
const path = require('path');
const nodeExternals = require('webpack-node-externals');
const HtmlWebPackPlugin = require("html-webpack-plugin");
module.exports = [clientConfig, serverConfig]; // Error: Array of functions that returns the object fails
//module.exports = env => [clientConfig(env), serverConfig(env)]; // Error: Function that return an array of objects fails
//module.exports = [clientConfig(), serverConfig()]; // Error: Array of objects fails
//module.exports = clientConfig; // OK: The first function alone works
//module.exports = serverConfig; // OK: The other function alone works
function serverConfig(env) {
return {
target: 'node',
// ...
};
}
function clientConfig(env) {
return {
target: 'web',
//...
};
}
Full code here.
Related issue: https://github.com/webpack/webpack-cli/issues/570#issuecomment-499093581
Upvotes: 1
Views: 1726
Reputation: 20162
Try to use another version of webpack
"webpack": "4.20.2"
I have seen that there are some people report that that have this issue when they using webpack 4.30 and above
Also try to use HtmlWebPackPlugin that have version above "4.0.0-alpha"
Then delete your package-lock.json and node_modules then run npm i again
Update:
Make sure to run --watch
in your command line
Upvotes: 1