Skip to content

Vite Polyfill Issue (Solved by Me) #111

@lukasdobbbles

Description

@lukasdobbbles

This took me a few hours to solve. The issue is that Vite by default doesn't polyfill. This leads to errors with the util package.

Errors

Uncaught TypeError: Cannot read properties of undefined (reading 'custom')
Image

Solution

npm i util

vite.config.js

import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  resolve: {
    alias: {
      util: "util/",
    },
  },
  define: {
    "process.env": { NODE_ENV: "development" }, // util expects a process.env
  },
});

Maybe instead of util.inspect you could just use JSON.stringify. Otherwise, this might be helpful to include in the docs or mention this somewhere.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions