Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tricking webpack makes webpack spit out ugly warnings #742

Closed
atombrenner opened this issue Mar 3, 2019 · 18 comments · Fixed by #776
Closed

Tricking webpack makes webpack spit out ugly warnings #742

atombrenner opened this issue Mar 3, 2019 · 18 comments · Fixed by #776
Labels
external The issue related to an external project 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt

Comments

@atombrenner
Copy link

atombrenner commented Mar 3, 2019

Issuehunt badges

What would you like to discuss?

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!

@sindresorhus
Copy link
Owner

sindresorhus commented Mar 3, 2019

We need webpack/webpack#8826

I have been asking the Webpack team for years to add a way to ignore require calls, but they have been unresponsive.

@sindresorhus
Copy link
Owner

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.

@atombrenner
Copy link
Author

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.

@sindresorhus
Copy link
Owner

@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.

@sindresorhus
Copy link
Owner

We could try this trick instead: https://twitter.com/kamilogorek/status/1102272038411137025

@szmarczak szmarczak added the external The issue related to an external project label Mar 4, 2019
@szmarczak
Copy link
Collaborator

@sindresorhus eval or the module.require thing?

@sindresorhus
Copy link
Owner

module.require

@IssueHuntBot
Copy link

@IssueHunt has funded $40.00 to this issue.


@IssueHuntBot
Copy link

@sindresorhus has rewarded $36.00 to @szmarczak. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

@SaadbinWaheed
Copy link

SaadbinWaheed commented Apr 22, 2020

@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.

@szmarczak
Copy link
Collaborator

Got 9.6.0 doesn't use TypeScript.

@SaadbinWaheed
Copy link

How does adding it to 'externals' solve it?

@szmarczak
Copy link
Collaborator

Don't know as I don't use webpack, but you can try out got@11.0.2, which does use TypeScript.

@SaadbinWaheed
Copy link

SaadbinWaheed commented Apr 22, 2020

Thank you but the original question relates to Webpack as well, and upgrading got didn't change anything.

@szmarczak
Copy link
Collaborator

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?

@szmarczak
Copy link
Collaborator

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.

@SaadbinWaheed
Copy link

can you try just loading @sindresorhus/is instead of Got and see if the error still exists?

I am using another node module that in turn is using got.

@SaadbinWaheed
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external The issue related to an external project 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants