esbuild-plugin-polyfill-node
esbuild-plugin-polyfill-node copied to clipboard
Global Polyfill is not injected even though I asked nicely
Despite specifying in my config, the polyfill for global to be set at globalThis does not seem to work on my configuration. Here is my config (Gulp):
esbuild({
outdir: "./scripts/",
bundle: true,
format: "esm",
platform: "neutral",
packages: undefined,
sourcemap: "external",
loader: {
".ts": "ts",
".md": "empty",
},
external: ["@minecraft/server", "@minecraft/server-ui"],
mainFields: ["main", "module"],
plugins: [
nodePolyfill.polyfillNode({
polyfills: {
buffer: true,
process: true,
stream: true,
_stream_readable: true,
_stream_writable: true,
_stream_transform: true,
_stream_duplex: true,
_stream_passthrough: true,
console: false,
},
globals: {
process: true,
global: true,
buffer: true,
navigator: true,
},
}),
],
})
)
Running my code runs returns error RefrenceError: 'global' is not defined. Any idea why this could be happening? The other globals work fine.
Changing line 183 in index.ts to:
build.initialOptions.inject.push(
resolve(dirname(filename), "../polyfills/global.js"),
);
seems to work. I haven't submitted a pull request because I imagine that build.initialOptions.inject wasn't used for a reason i don't know as I've never worked on esbuild plugins. __dirname, buffer, process, and navigator all do it this way, but global and __filename dont use build.initialOptions.inject. Is it included in some other polyfill that I'm not using?