Registry / http-networking / path-browserify

path-browserify

JSON →
library1.0.1jsnpmunverified

`path-browserify` provides a browser-compatible implementation of the Node.js `path` module, designed primarily for environments where the native Node.js module is unavailable, such as web browsers. It is commonly used as a transparent polyfill by JavaScript bundlers like Browserify and Webpack, often eliminating the need for direct installation in many projects. The current stable version, v1.0.1, mirrors the Node.js 10.3.0 `path` API, ensuring consistent behavior for POSIX-style path operations. Unlike the full Node.js module, `path-browserify` only implements POSIX functions and does not include Windows-specific (`path.win32`) utilities. Releases are typically driven by updates to the Node.js `path` module, with a focus on porting features and bugfixes directly from the Node.js core to maintain strict API parity. This approach makes it a reliable choice for projects needing Node.js `path` functionality in browser contexts without introducing new APIs.

npm install path-browserify
INSTALL
IMPORT
SIG · PATH-BROWSERIFY
P
path-browserify
http-networkingjavascriptv1.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.

path
const path = require('path-browserify')
import path from 'path-browserify'
This is the direct CommonJS import for the path-browserify module when installed explicitly. It exposes the Node.js 'path' module API.
path (aliased by bundlers)
const path = require('path')
import path from 'path'
When using bundlers like Browserify or Webpack, they typically alias the native Node.js 'path' module to 'path-browserify'. This allows you to import it simply as 'path' in your browser code, maintaining compatibility with Node.js source.

Demonstrates core path operations like joining, extracting components, resolving, and normalizing paths, mimicking the Node.js `path` module API in a browser environment.

const path = require('path-browserify'); // Or 'path' if using a bundler that aliases it // Example 1: Joining path segments const directory = '/users/documents'; const filename = 'report.pdf'; const fullPath = path.join(directory, filename); console.log('Joined path:', fullPath); // Expected: /users/documents/report.pdf // Example 2: Extracting path components const filePath = '/home/user/app/index.js'; console.log('Basename:', path.basename(filePath)); // Expected: index.js console.log('Dirname:', path.dirname(filePath)); // Expected: /home/user/app console.log('Extname:', path.extname(filePath)); // Expected: .js // Example 3: Resolving relative paths const from = '/data/files'; const to = '../../temp/log.txt'; const resolvedPath = path.resolve(from, to); console.log('Resolved path:', resolvedPath); // Expected: /temp/log.txt (simplified for example) // Example 4: Normalizing a path const uglyPath = '/foo//bar/./baz/../qux'; console.log('Normalized path:', path.normalize(uglyPath)); // Expected: /foo/bar/qux
Debug
Known issues
breakingStarting with v1.0.0, path methods now strictly throw errors when called with arguments that are not strings. This aligns its behavior with Node.js v10.3.0.
fix
Ensure all arguments passed to `path-browserify` methods are of type string. Validate input types before calling path functions.
affects: >=1.0.0
gotcha`path-browserify` only implements the POSIX-specific functions of the Node.js `path` module. Windows-specific (e.g., `path.win32`) methods are not available and will result in errors if attempted.
fix
Develop with only POSIX path conventions (e.g., forward slashes). If cross-platform path handling is critical, consider using a higher-level abstraction or conditional logic for Node.js environments.
affects: >=0.0.1
gotchaThe API of `path-browserify` currently matches Node.js 10.3.0. Newer features or API changes introduced in later Node.js versions' `path` module may not be present.
fix
Refer to the Node.js 10.3.0 path documentation for the exact API surface. If a newer `path` feature is required, check if it has been backported or consider alternative browser-compatible path utilities.
affects: >=0.0.1
gotcha`path-browserify` is primarily intended as a transparent polyfill included by bundlers (like Browserify or Webpack). Direct installation and usage might only be necessary in niche scenarios where a bundler isn't used or specific aliasing is required.
fix
In most web projects, rely on your bundler's default behavior for handling the Node.js `path` module. Only install directly if you have a specific reason to override or use it standalone.
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: Path must be a string. Received type [number|object|boolean]
A `path-browserify` method was called with one or more arguments that were not strings, which is not permitted since v1.0.0.
fix
Ensure all arguments passed to `path` methods (e.g., `path.join`, `path.basename`) are strictly strings. Coerce non-string values to strings or validate inputs before calling.
TypeError: Cannot read properties of undefined (reading 'join') or TypeError: path.win32 is not a function
This typically occurs when attempting to use Windows-specific path functions (like `path.win32.join`) that are not implemented in `path-browserify`, or trying to access the `win32` property which is absent.
fix
Only use POSIX-style path operations available directly on the `path` object (e.g., `path.join`, `path.basename`). `path-browserify` does not support Windows path conventions.
Upgrade
Version history
1.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
path-browserify — npm install path-browserify · libregistry