davidmyersdev / vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments.
MIT License
301 stars 22 forks source link

Warning on "use client" directive when using plugin alongside react #49

Closed KholdStare closed 11 months ago

KholdStare commented 11 months ago

When using this plugin alongside some react libraries, running a vite build results in a spew of errors like:

../node_modules/wagmi/dist/index.js (1:0) Module level directives cause errors when bundled, "use client" in "../node_modules/wagmi/dist/index.js" was ignored.

There are a bunch of issues filed in several libraries, but I think something is happening when using both this plugin and react, when dependencies use the new use client directive. See this issue in the rollup project:

https://github.com/rollup/rollup/issues/4699

I have created a small stackblitz environment where running npm run build will result in these warnings:

https://stackblitz.com/edit/vitejs-vite-pcpqdr?file=vite.config.ts

The key thing to note is that just removing this plugin fixes all the warnings. So there is some funky interaction.

KholdStare commented 11 months ago

Looks like this might have been fixed: https://github.com/rollup/rollup/issues/4699#issuecomment-1770565073

Nope still seeing it. Updating vite in stackblitz didn't help either. Seems like it's similar to this issue: https://github.com/davidmyersdev/vite-plugin-node-polyfills/pull/45

KholdStare commented 11 months ago

This looks like it fixes the issue: https://github.com/davidmyersdev/vite-plugin-node-polyfills/pull/53

davidmyersdev commented 11 months ago

Released in v0.16.0.