vite-plugin-node-polyfills
vite-plugin-node-polyfills copied to clipboard
define globalThis if not defined
I'm using this plugin in a project that started throwing errors in some sub-dependency because globalThis wasn't defined yet when this code ran. This one-line change resolves those errors. :-)
yo @davidmyersdev any feedback?
Hey @artursapek. 👋 I just ran the tests, and it looks like some are failing and need to be updated. Would you mind updating those? I can merge once CI is passing.
This only happens in HMR mode on vite dev. In addition to globalThis error @artursapek mentioned, I also get this error after setting globalThis to {}.
@artursapek you need to update the test files to pass the tests;
Test files:
Add this line for all tests
globalThis = globalThis || window
Your branch
expect(result?.code).toEqual(formatWhitespace(`
import __buffer_polyfill from "/shims/buffer/dist/index.js"
import __global_polyfill from "/shims/global/dist/index.js"
import __process_polyfill from "/shims/process/dist/index.js"
globalThis = globalThis || window
globalThis.Buffer = globalThis.Buffer || __buffer_polyfill
globalThis.global = globalThis.global || __global_polyfill
globalThis.process = globalThis.process || __process_polyfill
Buffer.from("test");
`))
@artursapek also, please update your branch, as there are already many changes in the tests in the main branch that may affect the final result.