blakeembrey / blakeembrey/make-error-cause

Browser compatibility

Open
#50 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
69
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Thanks for this great package! :smile:

## Expectation

From `README.md`:

> Compatible with node.js and browsers

## Problem

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

https://github.com/blakeembrey/make-error-cause/blob/629c06daab581559387054fca6edfbb67a6718c6/src/index.ts#L2

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](https://github.com/blakeembrey/make-error-cause/files/14614263/repro.zip)

1. `npm install`
2. `npm run build`
```
> vite-starter@0.0.0 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](https://github.com/blakeembrey/make-error-cause/assets/10025342/ad670720-25e9-4307-a60d-19ab34063c6f)
Here you can see in the built code where it happened:
![image](https://github.com/blakeembrey/make-error-cause/assets/10025342/8992c05e-78fd-4cdb-be27-93cf68cbe05b)

## Possible solution

Coming soon ...

Contributor guide

No contributing guide indexed for this repository

Research direction

Start at src/index.ts, especially the util import referenced in the report, and reproduce the issue with the linked Vite project using npm install, npm run build, and npm run preview. The work is done when the package runs in a browser without the util externalization warning or util_1.inspect error while preserving the README's browser-compatibility claim.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.