# fs-browser-stub

> Stub node fs module in browser

Latest version **1.1.1** (published 2024-12-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install fs-browser-stub
pnpm add fs-browser-stub
yarn add fs-browser-stub
bun add fs-browser-stub
```

## Health

**Score 30/100 (F)** — status: maintenance-mode.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2024-12-24 |
| First published | 2020-01-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 6.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Chunpeng Huo |
| Maintainers | huochunpeng |
| Keywords | browser |

## Links

- npm: https://www.npmjs.com/package/fs-browser-stub
- Repository: https://github.com/dumberjs/fs-browser-stub
- Homepage: https://github.com/dumberjs/fs-browser-stub#readme
- Issues: https://github.com/dumberjs/fs-browser-stub/issues
- npm.io page: https://npm.io/package/fs-browser-stub

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2024-12-24
- 1.1.0 — 2024-12-23
- 1.0.1 — 2020-01-17
- 1.0.0 — 2020-01-15

## README

# fs-browser-stub ![CI](https://github.com/dumberjs/fs-browser-stub/workflows/CI/badge.svg)

Stub node fs module in browser.

`fs.readFile` is still a function, would not throw an error.
Only when user calls `fs.readFile()`, it then throw an error.

# What does this resolve?

By default, browserify/webpack/parcel/fusebox/dumber would stub `fs` module with nothing or an empty object `{}`.

I was confused why `@babel/core` v7.8.0+ does not work in browser anymore. It turns out the babel uses `gensync` and that checks the type of `sync` and `errback` options. It rejects if they are not `function`.
This new `fs` stub bypasses the issue.

From https://github.com/babel/babel/blob/master/packages/babel-core/src/gensync-utils/fs.js

```js
export const readFile = gensync<[string, "utf8"], string>({
  sync: fs.readFileSync,
  errback: fs.readFile,
});
```

---
_Source: https://npm.io/package/fs-browser-stub · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
