cyco130 / esbuild-plugin-polyfill-node

ESBuild plugin to polyfill Node.js built-ins geared towards edge environments.
MIT License
55 stars 8 forks source link

Error when using with Vite #13

Open secondl1ght opened 1 year ago

secondl1ght commented 1 year ago

When using with Vite I am getting the following error: The injected path "/node_modules/esbuild-plugin-polyfill-node/polyfills/__dirname.js" cannot be marked as external. Is there some extra config I need to do here?

cyco130 commented 1 year ago

It’s an ESBuild plugin. In what way are you using it with Vite?

robertsLando commented 1 year ago

Got the same error... I switched to this as suggested here: https://github.com/remorses/esbuild-plugins#plugins

cyco130 commented 1 year ago

Can I get a reproduction?

robertsLando commented 1 year ago

Here: https://github.com/mqttjs/MQTT.js/blob/main/examples/vite-example/vite.config.js

Just replace @esbuild-plugins/node-globals-polyfill with esbuild-plugin-polyfill-node

secondl1ght commented 1 year ago

Vite uses ESBuild (and Rollup) so you are able to use ESBuild plugins like this one. https://vitejs.dev/config/shared-options.html#esbuild

cyco130 commented 1 year ago

Got it. This is not a usage I have considered before. I'll have a look.

okular commented 1 year ago

@robertsLando how did you resolve this issue, i have been dealing with a very annoying issue that is similar to the one you had

robertsLando commented 1 year ago

I used the other package

mdiflorio commented 5 months ago

For anyone in the same situation as I was. There seems to be an issue with the way Vite loads esbuild plugins and isn't related to this package.

An alternative is to use vite-plugin-node-polyfills and in my case I had to installed next-tick as well.

Loading it into my main.tsx file like so:

// Polyfill for @azure/service-bus as vite-plugin-node-polyfills doesn't include it
import nextTick from 'next-tick';
process.nextTick = nextTick;