Description
Bug report
What is the current behavior?
Webpack tries to handle all require()
calls, even those not meant for browser usage. This makes it almost impossible to have a module that works in both Node.js and the browser, but has some added capabilities in Node.js.
Note that this is about authoring reusable npm packages, not end-user apps. I don't have the ability to set any Webpack config like the externals
option since I'm making packages other devs will consume.
This is the kind of awfulness we have to do because of Webpack: https://github.com/sindresorhus/ow/blob/d62a06c192b892d504887f0b97fdc842e8cbf862/source/utils/node/require.ts We have wasted countless of hours on this.
Prior discussion that went mostly ignored by the Webpack team: #196 (comment)
What is the expected behavior?
I expected to be able to annotate the code to make Webpack ignore certain require()
calls.
For example with a comment:
const require('chalk'); // webpack-ignore
I know for certain that this require()
call will not be used in the browser, so I should be able to have it in my source code without Webpack printing warnings to users or erroring out.
I need this as a module maintainer (not user).
Telling users to use the externals
config is out of the questions, as my package might be a dependency many levels down.
Some more examples of where I have to use awful code to work around Webpack:
Other relevant information:
webpack version: 4.29.0 (applies to any version though)
Node.js version: 10.15.0
Operating System: macOS 10.14.3
Additional tools: