Registry / tty-browserify

tty-browserify

JSON →
library0.0.1jsnpmunverified

`tty-browserify` provides a browser-compatible stub for the Node.js core `tty` module, enabling Node.js applications that use `require('tty')` to be bundled and run in a browser environment via Browserify. It primarily offers a `tty.isatty()` function which consistently returns `false` in the browser context, as true TTY (teletypewriter) devices do not exist in standard web browsers. Attempts to instantiate `tty.ReadStream` or `tty.WriteStream` directly in the browser will result in errors, reflecting the fundamental difference in I/O environments between Node.js CLI applications and web browsers. This package, currently at version 0.0.1, has not seen active development since its last release over eight years ago (January 2018) but remains a crucial underlying dependency for many legacy Browserify-based projects, evident by its high weekly download count despite its age. Its release cadence is effectively dormant, and its key differentiator is its role as a direct translation layer for a core Node.js API to the browser via Browserify's module resolution.

npm install tty-browserify
INSTALL
IMPORT
SIG · TTY-BROWSERIFY
T
tty-browserify
javascriptv0.0.1
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

tty
const tty = require('tty');
import * as tty from 'tty';
This package is an older CommonJS module. ESM `import` syntax will not work directly without a build step that handles CJS to ESM interop (e.g., via Browserify itself).
isatty
const isatty = require('tty').isatty;
import { isatty } from 'tty';
While `tty.isatty` is a named export conceptually, direct destructuring with `require` is typical for CommonJS. The function always returns `false` in browsers.

Demonstrates the core stubbed functionality of `tty-browserify`: `isatty` returning `false` and `ReadStream`/`WriteStream` throwing errors in a browser context. This code needs to be bundled with Browserify to run in a browser.

const tty = require('tty'); console.log('Testing tty-browserify functionality in a browser environment...'); // tty.isatty() always returns false in the browser const isStdoutTTY = tty.isatty(1); // File descriptor 1 typically for stdout console.log(`Is stdout a TTY? ${isStdoutTTY}`); // Attempting to create ReadStream/WriteStream throws an error try { new tty.ReadStream(); } catch (e) { console.error(`Attempting to create tty.ReadStream throws: ${e.message}`); } try { new tty.WriteStream(); } catch (e) { console.error(`Attempting to create tty.WriteStream throws: ${e.message}`); } // To run this code, first install browserify: npm install -g browserify // Then, bundle your code: browserify your_script.js -o bundle.js // And include bundle.js in an HTML file: <script src="bundle.js"></script>
Debug
Known issues
breakingAttempting to instantiate `tty.ReadStream` or `tty.WriteStream` will throw an error, as these functionalities are not implementable in a standard browser environment.
fix
Avoid using `new tty.ReadStream()` or `new tty.WriteStream()`. If Node.js `tty` streams are required, the application cannot run directly in a browser without significant architectural changes.
affects: >=0.0.1
gotcha`tty.isatty()` will always return `false` when running in a browser environment, regardless of the browser's console state. This can lead to unexpected behavior if code assumes TTY capabilities are partially emulated or detected.
fix
Design browser-compatible code paths that do not rely on TTY functionality, or explicitly handle the `false` return from `tty.isatty()`.
affects: >=0.0.1
deprecatedThe package `tty-browserify` has not been updated since January 2018 (version 0.0.1) and is effectively unmaintained. While it remains a critical transitive dependency for many Browserify projects, direct reliance or expectations of new features/bug fixes should be avoided.
fix
Evaluate whether your project still requires Browserify and its core module shims. For new projects, consider modern bundlers (e.g., Webpack, Rollup, Vite) which might offer more flexible or explicit polyfill strategies, or refactor to avoid Node.js-specific modules in browser code.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: tty.ReadStream is not a constructor
The `tty.ReadStream` class is a Node.js-specific concept for managing readable TTY streams, which cannot be implemented in a standard browser environment.
fix
Remove or conditionally guard calls to `new tty.ReadStream()`. Refactor code to use browser-native input mechanisms if interactive input is needed.
TypeError: tty.WriteStream is not a constructor
The `tty.WriteStream` class is a Node.js-specific concept for managing writable TTY streams, which cannot be implemented in a standard browser environment.
fix
Remove or conditionally guard calls to `new tty.WriteStream()`. Refactor code to use browser-native output mechanisms (e.g., `console.log`, DOM manipulation) instead.
ReferenceError: require is not defined
The `require` function is specific to CommonJS environments (like Node.js or bundled code) and is not natively available in browsers.
fix
Ensure your script is processed by Browserify (or another CommonJS-compatible bundler) and included correctly in your HTML. Use `browserify your_script.js -o bundle.js` and link `<script src="bundle.js"></script>`.
Upgrade
Version history
0.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
tty-browserify — npm install tty-browserify · libregistry