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

@tanstack/react-query-devtools is not working. #19

Closed joyfuI closed 1 year ago

joyfuI commented 1 year ago

codesandbox link: https://codesandbox.io/p/sandbox/vite-plugin-node-polyfills-92mi3n?file=%2Fvite.config.ts

The ReactQueryDevtools component doesn't show up in the bottom left corner of the preview, but if I comment out nodePolyfills() in vite.config.ts, it shows up again.

davidmyersdev commented 1 year ago

I'll have to dig into this more, but I'm thinking the react plugin must be injecting something into the browser that is relying on a certain API to not be polyfilled.

Barlow1 commented 1 year ago

Having the same issue here, would love to help out if possible.

Barlow1 commented 1 year ago

Here is another repro not using the react plugin and excluding every option possible. It is still not working: https://codesandbox.io/p/sandbox/optimistic-panini-95xb2d

davidmyersdev commented 1 year ago

I was able to determine that the process shim is what causes the dev tools to not work. My best guess is that the plugin relies on overriding process itself in dev. I need to think through how I want the interface to work, but I'll likely expose a way to disable the shims for process, global, and Buffer for either dev or build.

davidmyersdev commented 1 year ago

This has been fixed in v0.9.0. For your specific issue, you'll want to do something like this.

import { defineConfig } from 'vite'
import { nodePolyfills } from 'vite-plugin-node-polyfills'

export default defineConfig({
  plugins: [
    nodePolyfills({
      globals: {
        process: 'build',
      },
    }),
  ],
})