cyco130/esbuild-plugin-polyfill-node

Error when using with Vite

Opened this issue · 9 comments

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?

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

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

Can I get a reproduction?

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

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

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

okular commented

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

I used the other package

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;