davidmyersdev / vite-plugin-node-polyfills

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

Requiring node core module with trailing slash `/` ERROR #67

Closed paro-paro closed 6 months ago

paro-paro commented 6 months ago

@davidmyersdev

My original post here

As pointed in the previous thread, seems like the plugin fails due to an upstream dependency trying to import process/ instead of process.

Doing some digging I detected that the conflicting dependency was readable-stream which is a NodeJS official package. Looks like the trailing slash / syntax is intended... as explained here.

Do not really understand the rationale behind it since it feels like a workaround for browserify...

In any case, it would be great if we can expect a fix from the plugin side.

Thanks a lot for your help!

davidmyersdev commented 6 months ago

Repro: https://stackblitz.com/edit/github-yd3jt3?file=nuxt.config.ts

davidmyersdev commented 6 months ago

This is fixed in v0.19.0.

Updated repro: https://stackblitz.com/edit/github-yd3jt3-9mmv9s?file=package.json

paro-paro commented 6 months ago

Hi @davidmyersdev

Thanks a lot for the quick fix. The trailing slash issue is indeed fixed in the new version. However, the nuxt production build is still failing for me with a different error from #41.

Now, the exports object seems to be injected in the final bundle, making the app crash on production.

Reproduction: https://stackblitz.com/edit/github-yd3jt3?file=nuxt.config.ts

  1. Running nuxt build and nuxt preview will return an "exports is not defined" error.

The reproduction uses nuxt 3.8.2 (which is the version I am currently using) but I have also tested the latest 3.9.0 release (which leverages vite 5.x) and no luck either.

Let me know if I could expect any help from the plugin side.

Thanks in advanced!

paro-paro commented 6 months ago

Hi @davidmyersdev

Just posting here that I was able to fix my issue thanks to the awesome guys at nuxt. In the end, it was just a matter of targeting a different polyfill library in the aliasing property.

Here is some context in case you find it useful.

Thanks for the plugin!!

pi0 commented 6 months ago

@davidmyersdev I would be more than happy to help if you like to migrate the polyfill backend to unenv, it should make the plugin much more usable.

davidmyersdev commented 5 months ago

Hey @pi0! I would love to migrate to unenv! I'll take a look and see if I have any questions for you.