Skip to content

Browser compatibility #50

@rudolfbyker

Description

@rudolfbyker

Thanks for this great package! 😄

Expectation

From README.md:

Compatible with node.js and browsers

Problem

However, it imports from "util", which is only available in Node JS:

import { inspect } from "util";

And I'm seeing this error in some of my projects:

Uncaught TypeError: util_1.inspect is undefined

Reproduction

Here is a very minimal Vite project that demonstrates the problem: repro.zip

  1. npm install
  2. npm run build
    > [email protected] build
    > vite build
    
    vite v5.1.6 building for production...
    [plugin:vite:resolve] [plugin vite:resolve] Module "util" has been externalized for browser compatibility, imported by "/home/dolf/tmp/20240315-make-error-cause/repro/node_modules/make-error-cause/dist/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
    ✓ 11 modules transformed.
    dist/index.html                0.25 kB │ gzip: 0.19 kB
    dist/assets/index-B4nqUxqB.js  7.73 kB │ gzip: 2.32 kB
    ✓ built in 84ms
    
    Note the warning above. See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.
  3. npm run preview
  4. Open browser and look in the console to see the error:
    image
    Here you can see in the built code where it happened:
    image

Possible solution

Coming soon ...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions