Headers polyfill should print a warning instead of throwing.

This issue has been tracked since 2023-03-03.

Describe the bug
Some platforms already polyfill Headers, breaking @bufbuild/connect-node due to https://github.com/bufbuild/connect-es/blob/a717308d2268f5337e8983d5dfb5636cb18d69e6/packages/connect-node/src/node-headers-polyfill.ts#LL28C5-L28C80. This should log a warning instead.

To Reproduce

Polyfill headers and then import @bufbuild/connect-node.

Environment (please complete the following information):

  • @bufbuild/connect-node version: 8.1.0
  • Node.js version: 16.14.2

Additional context
Add any other context about the problem here.

dicarlo2 wrote this answer on 2023-03-08

It would actually be better to not polyfill at all. Very odd that a library is polluting the global namespace. Instead, just import Headers from somewhere within connect-node and export either globalThis.Headers if defined or your polyfilled library.

timostamm wrote this answer on 2023-03-08

That is certainly a bug. The code should definitely not crash below v18 if Headers already exists, and I don't even think it should produce a warning.

I agree that modifying globals is far from ideal. What you suggest is not a great option for us, because large parts of connect-es are universal, and we would pull the polyfill into bundles for web browsers.

To put things into perspective, Node.js v17 is already EOL, and v16 will be EOL in six months, so I hope you'll understand if we rather focus on other features.

Thank you for putting up the bug report!

smaye81 wrote this answer on 2023-03-08

@dicarlo2 This should now be fixed in our latest release v0.8.2.

dicarlo2 wrote this answer on 2023-03-08

Awesome, thanks!

More Details About Repo
Owner Name bufbuild
Repo Name connect-es
Full Name bufbuild/connect-es
Language TypeScript
Created Date 2022-02-16
Updated Date 2023-03-24
Star Count 852
Watcher Count 20
Fork Count 33
Issue Count 17

YOU MAY BE INTERESTED

Issue Title Created Date Updated Date