Skip to content

feat: optionally provide empty polyfills#132

Merged
imranbarbhuiya merged 1 commit intoimranbarbhuiya:mainfrom
markdalgleish:empty-polyfills
Jul 17, 2023
Merged

feat: optionally provide empty polyfills#132
imranbarbhuiya merged 1 commit intoimranbarbhuiya:mainfrom
markdalgleish:empty-polyfills

Conversation

@markdalgleish
Copy link
Contributor

I've been investigating issues some Remix users have had since we migrated from esbuild-plugin-polyfill-node.

One issue is that the fs polyfill is throwing an error when building for Cloudflare since it sets up a file system watcher as a top-level side effect:

service core:user:worker: Uncaught Error: Some functionality, such as asynchronous I/O, timeouts, and generating random values, can only be performed while handling a request.

What's interesting is this wasn't happening with our old polyfill setup even though it was also built on JSPM browser polyfills. It turns out that previously the fs polyfill was actually an empty module by default (among others): https://github.com/cyco130/esbuild-plugin-polyfill-node/blob/9afcb6abaf9062a15daaffce9a14e478b365139c/src/index.ts#L143-L149. I can reproduce the same error with our old polyfills if I explicitly enable the fs polyfill.

In order to support this scenario, this PR extends the modules option to support an object that can optionally configure empty polyfills, e.g.

nodeModulesPolyfillPlugin({
  modules: {
    fs: 'empty',
    crypto: true,
  }
})

Status and versioning classification:

  • Code changes have been tested and working fine, or there are no code changes
  • This PR changes the library's interface (methods or parameters added)

@imranbarbhuiya imranbarbhuiya merged commit 6642f2f into imranbarbhuiya:main Jul 17, 2023
@imranbarbhuiya
Copy link
Owner

imranbarbhuiya commented Jul 17, 2023

Thanks ❤️, released in https://github.com/imranbarbhuiya/esbuild-plugins-node-modules-polyfill/releases/tag/v1.3.0

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants