I use got 9.6.0 with webpack 4.29.6 and target a node application. Webpack throws this ugly warning
WARNING in ./node_modules/got/source/request-as-event-emitter.js 72:18-25
Critical dependency: require function is used in a way in which dependencies cannot be statically extracted
The reason for this is the following tricky code in request-as-event-emitter.js line 42
const r = ({x: require})['yx'.slice(1)]; // Trick webpack
const electron = r('electron');
If I replace those lines with
const electron = require('electron');
and configure webpack to treat 'electron' as an external dependency everything is fine without warnings.
Maybe this hack was necessary once, but it would nice to use something more standard that works out of the box.
szmarczak earned $40.00 by resolving this issue!
- Checkout the Issuehunt explorer to discover more funded issues.
- Need some help from other developers? Add your repositories on Issuehunt to raise funds.
We need https://github.com/webpack/webpack/issues/8826
I have been asking the Webpack team for years to add a way to ignore require calls, but they have been unresponsive.
Maybe this hack was necessary once, but it would nice to use something more standard that works out of the box.
There's nothing standard, that's the problem.
I'm also not a Webpack fan, but you can configure webpack to ignore certain requires (e.g. 'electron') like this: webpack.config.js l
module.exports = {
externals: ['zlib', 'electron']
}
If you used the standard require('electron') instead of tricking webpack, users would be able to configure webpack to make the warning go away.
@atombrenner If Got is deep in the dependency-tree, people will not understand why they would suddenly get such a warning, and most don't even know about the externals trick.
It's just silly that we have to waste so much energy trying to "trick" Webpack. This is far from the first time I had to waste time on Webpack related things.
We could try this trick instead: https://twitter.com/kamilogorek/status/1102272038411137025
@sindresorhus eval or the module.require thing?
module.require
@issuehunt has funded $40.00 to this issue.
@sindresorhus has rewarded $36.00 to @szmarczak. See it on IssueHunt
@sindresorhus ,I am using got 9.6.0 and am still getting the above warnings after I updated to openid-client's latest version. Perhaps a very noob question considering the issue is resolved.
Additionally getting:
(Emitted value instead of an instance of Error) Cannot find source file '../source/index.ts': Error: Can't resolve '../source/index.ts' in 'C:\Source_imodelSchemaManagementService\iModelSchemaManagementService\node_modules\@sindresorhus\is\dist'
Adding it as an external dependency in webpack.config fixes it but I want to avoid doing that.
Got 9.6.0 doesn't use TypeScript.
How does adding it to 'externals' solve it?
Don't know as I don't use webpack, but you can try out [email protected], which does use TypeScript.
Thank you but the original question relates to Webpack as well, and upgrading got didn't change anything.
I doubt it's Got failure (I don't say it's not), can you try just loading @sindresorhus/is instead of Got and see if the error still exists?
If you use Got 9.6.0 then I don't think it's Got's fault because Got 9.6.0 does not use TypeScript at all.
can you try just loading
@sindresorhus/isinstead of Got and see if the error still exists?
I am using another node module that in turn is using got.
If you use Got 9.6.0 then I don't think it's Got's fault because Got 9.6.0 does not use TypeScript at all.
As I said, I did try the newest version as well.
Most helpful comment
@atombrenner If Got is deep in the dependency-tree, people will not understand why they would suddenly get such a warning, and most don't even know about the
externalstrick.It's just silly that we have to waste so much energy trying to "trick" Webpack. This is far from the first time I had to waste time on Webpack related things.