I have encountered an error when using the latest version of Webpack (5.1.0). It looks like the configuration is throwing an error because the validation schema is too restrictive. Here is my webpack configuration file in a gist, and the error message I am seeing.
Webpack.config.js
https://gist.github.com/adarshbhat/3ec5950b66b78102da0cf46e51a3d633
Error
[webpack-cli]
Invalid configuration object. Webpack has been initialized using a configuration object that does not match the API schema.
- configuration.node should be one of these:
false | object { __dirname?, __filename?, global? }
-> Include polyfills or mocks for various node stuff.
Details:
* configuration.node has an unknown property 'module'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'net'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
* configuration.node has an unknown property 'fs'. These properties are valid:
object { __dirname?, __filename?, global? }
-> Options object for node compatibility features.
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! [email protected] start: `webpack serve`
npm ERR! Exit status 2
I am attempting to use a parser generator library (antlr4) that works both in a Node.js environment, as well as in browsers. It looks like the library code is requiring global objects like fs, and if it is empty, assumes that it is in a browser environment. According to the documentation of Antlr4 and that of Webpack , this is a supported configuration file. But it is not working. Please help.
Versions
- webpack: 5.1.0
- webpack-cli: 4.0.0
- webpack-dev-middleware: 3.7.2
- webpack-dev-server: 3.11.0
Update (Oct 29 2020)
Antlr JavaScript documentation has now been updated with the new configuration for Webpack 5
fs
andnet
modules in browsers which is impossible – Harshrequire
those modules. If it receives an empty object, then it assumes that it is in a browser environment. This is how the library is able to function both in Node.js environment and browser environment. It looks like other people have been able to get this to work in older versions of Webpack. – Tidewindow
ordocument
is defined:if (typeof window !== 'undefined') ...
if not then you are in node.js – Harshantlr4
library package. I am just the poor chap trying to use it. My hope is that Webpack fixes this if this is a supported configuration. – Tide