Skip to content

Docs: explain how to do node polyfills #21385

@mtmacdonald

Description

@mtmacdonald

Documentation is

  • Missing
  • Outdated
  • Confusing
  • Not sure?

Explain in Detail

Hi! Can we please have some docs on how to do node polyfills in modern (Rolldown) vite?

I understand the project's decision not to do this automatically (since frontend packages should not be relying on node functions). But in reality, not all mainstream NPM packages have caught up, and node polyfills are still sometimes needed.

I think many in the community are relying on the vite-plugin-node-polyfills NPM package, but my impression is it's not being actively maintained or upgraded for rolldown-vite and Vite 8 (e.g. see recent bug tickets on security, optimizeDeps.esbuildOptions warnings, runtime error regression).

I've also seen projects using:

And recently found

  • rolldown-plugin-node-polyfills, but it wasn't immediately clear to me if that's directly usable in Vite, or if it applies to both PROD and DEV builds.

Currently all I can find in the Vite docs is this statement, but no tips on how.

Image

Your Suggestion for Changes

Could we please have an example / recommendation in the docs on how to add a polyfill for a node dependency (e.g. Buffer). That would really help me unblock two projects if vite-plugin-node-polyfills doesn't get some maintenance for Vite 8 support. Thank you!

Reproduction

https://vite.dev/guide/troubleshooting#module-externalized-for-browser-compatibility

Steps to reproduce

N/A (docs update request)

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions