Skip to content

[Webpack 5] Automatic Node.js Polyfills Removed #11282

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

Closed
hanford opened this issue Aug 5, 2020 · 7 comments
Closed

[Webpack 5] Automatic Node.js Polyfills Removed #11282

hanford opened this issue Aug 5, 2020 · 7 comments
Labels

Comments

@hanford
Copy link

hanford commented Aug 5, 2020

Hello Webpack team!

First of all, huge thank you to everything that Webpack has become. I've been happily using webpack for 5 or 6 years now and it's critical software for me.

I'm super excited about Webpack 5 (Especially Filesystem cache & Module Federation). I noticed that the nodejs polyfills are removed which a few my projects rely on, that's totally cool ... but I'm not sure what the best way to migrate that code is.

Seems like most instances are in dependencies of dependencies, and after searching through the docs I wasn't able to find a migration for this specific change.

Is there a Webpack 5 compatible way of achieving the same thing? Do I polyfill these libraries in my application code?

Thanks again!

@alexander-akait
Copy link
Member

Here docs https://github.com/webpack/changelog-v5#automatic-nodejs-polyfills-removed

Plus you can use alias for this https://webpack.js.org/configuration/resolve/#resolvealias

@hanford
Copy link
Author

hanford commented Aug 5, 2020

Thanks!

@hanford hanford closed this as completed Aug 5, 2020
@hanford
Copy link
Author

hanford commented Aug 6, 2020

Also came across this!

https://medium.com/@sanchit3b/how-to-polyfill-node-core-modules-in-webpack-5-905c1f5504a0

@hanford
Copy link
Author

hanford commented Aug 11, 2020

@evilebottnawi So I'm able to load my own Node polyfills and that's working great

I ran into another situation that's pretty interesting, I'm depending on this library which is using process.cwd() as a global (not importing process) ... and so my process mocks aren't loaded

Any ideas on how to solve or mock this use case?

If this is something that Webpack isn't concerned about, I'm happy to move this issue you to the other libraries repo, but figured this may be something that a lot of users migrating to WP5 will run into.

@hanford hanford reopened this Aug 11, 2020
@alexander-akait
Copy link
Member

alexander-akait commented Aug 11, 2020

You need to open an issue in library for browsing supporting or you can use https://www.npmjs.com/package/process (just put import 'process';), some libraries can be incompatibility with browsers env, we can't fix it

@hanford
Copy link
Author

hanford commented Aug 11, 2020

Thanks @evilebottnawi I'll move my issue to the other repo

@hanford hanford closed this as completed Aug 11, 2020
hanford added a commit to hanford/vfile that referenced this issue Aug 11, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Hello maintainers!

First of all, thanks for working on vfile, I've been using this a lot (especially with remark) and it's been a lifesaver.

tl;dr, webpack versions 1-4 used to automatically polyfill node.js libraries and the next version, version 5 doesn't.

While migrating a larger project of mine, I ran into a scenario where vfile was breaking because it wasn't loading my `process` polyfill because `vfile` is using `process` as a global.

Here is the related webpack issue: webpack/webpack#11282
@roman-hordiichuk
Copy link

roman-hordiichuk commented May 17, 2024

Found solution for Angular and particularly sockJS nested dev-dependency of eventsource lib. Perhaps not the prettiest solution, though but it still works.
node: 16.20.2
npm: 8.19.4 (please aware, override works only with npm >= v8.3)

So you need the following steps:

  1. Install https://www.npmjs.com/package/event-source-polyfill
  2. Override required dependencies in package.json, in my case it was:
"overrides": {
    "sockjs-client": {
      "eventsource": "npm:event-source-polyfill"
    } 

So it changes your nested dependency by entirely different lib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants