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
feat: experimental Node.js imports compatibility for client-side #25028
Conversation
Run & review this pull request in StackBlitz Codeflow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this. I am wondering if we should default it to false
, however - so it can be an escape hatch for users who need it.
I am thinking it would still be better for users to be aware of the fact that they are using node dependencies in the browser, so they can potentially bail out or switch to a different library.
What do you think?
I am also happy to keep it disabled by default feel free to commit before merge. But it kinda takes away the point of build-in integration because users can already easily do same unenv client support from Currently we do same mocks on server-side for non Nodejs targets it makes the behavior more consistant for library support when universally imported in SSR. Meanwhile i agree about keeping users aware of that, i guess as a followup we can show a warn about dependencies that use Node.js API and guiding users about prefering an alternative lib (if they are lucky enough to have alt!) with dep graph this should be straight forward. In many cases such aliases will be tree-shaken also BTW but they are only in dependency graph of rollup. |
(i am also not happy about top level |
Okay, that's a persuasive reason to enable by default. But I'd suggest there might be merit in logging or warning users when polyfills are injected... On the schema, what if we use a single We could also consider making the key more generic, as the average user who wants to configure this might be unaware of unenv or what it is or does... Finally, if there's more testing to be done, we could release this under |
Mind you, in the current state what we do is only enable access to While I think it should be something really safe to be enabled by default, I have moved it behind |
β Live Preview ready!
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
beautiful. π
I would actually be fine enabling by default (with a warning if needed) given there's no bundle cost - but let's see usage and we can always enable in future.
π Linked issue
resolves #12786, #25016
β Type of change
π Description
This PR allows using libraries for code that depends on Node.js API by polyfilling them using unjs/unenv which is already used for server bundles (via nitro and presets).
Notes:
node:
and node imports are supportedprocess
,Buffer
, etc needs to be manually importedInjecting globals:
To avoid accidentally increasing bundle size if only a code-syntax depends on
Buffer
check (that adds~42Kb
, and Vue deps already do this!), auto injections are disabled. But they can be easily imported fromnode:
Inside a Nuxt plugin, they can be also polyfilled (by User's risk!)
In next iterations we might find smarter ways to safely inject them.
π Checklist