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

i get error after i build ReferenceError: process is not defined #21

Closed melsayedgit closed 11 months ago

melsayedgit commented 1 year ago

ReferenceError: process is not defined

davidmyersdev commented 1 year ago

Hey there. 👋 Can you share your Vite config or provide a reproduction for me?

isirode commented 1 year ago

Hello, I've encountered the same/similar error.

My config was the default one, but I've tried to play with the globals properties (disabling process and global) since I only needed to polyfill 'path'.

It did not worked either way.

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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    nodePolyfills({
      // To exclude specific polyfills, add them to this list.
      exclude: [
        'fs', // Excludes the polyfill for `fs` and `node:fs`.
      ],
      // Whether to polyfill specific globals.
      globals: {
        Buffer: true, // can also be 'build', 'dev', or false
        global: true,
        process: true,
      },
      // Whether to polyfill `node:` protocol imports.
      protocolImports: true,
    }),
  ],
})

My error was slighly different, it was 'Uncaught TypeError: Cannot read properties of undefined (reading 'isTTY')', from this code (from jest-util):

var _default =
  !!process.stdout.isTTY && process.env.TERM !== 'dumb' && !_ciInfo().isCI;
exports.default = _default;

My context is specific, I am running Mocha tests using WebDriverIO browser runner (which use Vite).

I do not have this error when I am not using the plugin.

I ended up using path-browserify manually, as an alias.

davidmyersdev commented 1 year ago

Hey @isirode. I still need a reproduction in order to debug this. If you can provide a StackBlitz or CodeSandbox example of this error, I should be able to diagnose the issue and get a fix out.

isirode commented 11 months ago

Hi, sorry, I had forgotten about it since I did not used it in the end, I will try to provide a reproduction when I have time.

davidmyersdev commented 11 months ago

I'm closing this since I cannot reproduce it. Please open a new issue if this is still a problem.