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

refactor(remix-dev): replace esbuild-plugin-polyfill-node with esbuild-plugins-node-modules-polyfill #6414

Closed
wants to merge 6 commits into from

Conversation

LukeAskew
Copy link
Contributor

@LukeAskew LukeAskew commented May 17, 2023

esbuild-plugin-polyfill-node was introduced as part of #5274. Unfortunately, that plugin introduces some issues:

Screenshot 2023-05-17 at 10 41 12 AM

This change replaces esbuild-plugin-polyfill-node with esbuild-plugins-node-modules-polyfill, which also uses jspm (via modern-node-polyfills).


Closes: #6380

Testing Strategy: Replaced plugin in my remix app and did not encounter errors.

@changeset-bot
Copy link

changeset-bot bot commented May 17, 2023

⚠️ No Changeset found

Latest commit: adc3621

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented May 17, 2023

Hi @LukeAskew,

Welcome, and thank you for contributing to Remix!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at [email protected].

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented May 17, 2023

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@ivogt
Copy link
Contributor

ivogt commented May 18, 2023

I've noticed that the esbuild-plugin-polyfill-node also polyfills node:async_hooks etc (makes them unavailable with a stub unimplemented). Basically making compatibility_flags = [ "nodejs_compat" ] unusable.

Is this PR handling these correctly and we can use nodejs_compat?

@LukeAskew
Copy link
Contributor Author

@ivogt If I understand correctly this should only affect browser code so you should be able to use node:async_hooks in Cloudflare's compat mode since it's Node.js. I'm not sure how you'd implement async_hooks for browser code. (jspm/jspm-core#28)

@ivogt
Copy link
Contributor

ivogt commented May 18, 2023

@LukeAskew Sorry, let me clarify. So, for Cloudflare Workers the build is handled as 'neutral'. Since workers support nodejs_compat and there are couple of modules with node: prefix (e.g. node:utils and node:async_hooks which these polyfills override. In https://github.com/remix-run/remix/pull/6414/files#diff-833c098a2a1bb29fb7094fb9a15af9f299cadbd1fb35bcc0cd7f078807fa8358 we remove the imports of node:*module* which prevents us from using them.

I suggest we exclude the workers from the polyfill e.g. ctx.config.serverPlatform !== "node" && ctx.config.serverPlatform !== "neutral" .

Don't think we need to polyfill for workers runtime, do we?

Thank you

@ivogt
Copy link
Contributor

ivogt commented May 18, 2023

Also mentioned here #6348

@bryce-pearce
Copy link

bryce-pearce commented May 23, 2023

this would also likely close #6259

#5858
#6280
#6284
#6290

as well as a few more I believe

@frandiox
Copy link
Contributor

Thanks for the PR. This should also close #6348 thanks to the last commit.

@DaniBitZesty
Copy link

Hello, I'm working on a project that's quite dependent on this fix. Will this be merged soon? 🙏

@machour machour requested a review from pcattori May 31, 2023 15:45
@BrycePearce
Copy link

Hello, I'm working on a project that's quite dependent on this fix. Will this be merged soon? 🙏

likewise

@MichaelDeBoey
Copy link
Member

Superseded by #6547

@jacob-ebey
Copy link
Member

I have broken this PR up into two parts:

  1. Replace the polyfill package: refactor(remix-dev): replace esbuild-plugin-polyfill-node with esbuild-plugins-node-modules-polyfill #6562
  2. Add config option for if polyfills are used or not: feat(remix-dev): introduce serverNodeBuiltinsPolyfill config option #6547

We can't accept this as is as it changes existing behavior for users. Thank you for the contribution and pointing us at a better alternative :)

@jacob-ebey jacob-ebey closed this Jun 7, 2023
@jacob-ebey
Copy link
Member

Part 1 merged: #6562

@brandonpittman
Copy link

Testing Strategy: Replaced plugin in my remix app and did not encounter errors.

I did.

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

Successfully merging this pull request may close these issues.

9 participants