{"id":11528,"library":"path-browserify","title":"Node.js Path Module for Browsers","description":"`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.","status":"active","version":"1.0.1","language":"javascript","source_language":"en","source_url":"git://github.com/browserify/path-browserify","tags":["javascript","browser","browserify","path"],"install":[{"cmd":"npm install path-browserify","lang":"bash","label":"npm"},{"cmd":"yarn add path-browserify","lang":"bash","label":"yarn"},{"cmd":"pnpm add path-browserify","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is the direct CommonJS import for the path-browserify module when installed explicitly. It exposes the Node.js 'path' module API.","wrong":"import path from 'path-browserify'","symbol":"path","correct":"const path = require('path-browserify')"},{"note":"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.","wrong":"import path from 'path'","symbol":"path (aliased by bundlers)","correct":"const path = require('path')"}],"quickstart":{"code":"const path = require('path-browserify'); // Or 'path' if using a bundler that aliases it\n\n// Example 1: Joining path segments\nconst directory = '/users/documents';\nconst filename = 'report.pdf';\nconst fullPath = path.join(directory, filename);\nconsole.log('Joined path:', fullPath); // Expected: /users/documents/report.pdf\n\n// Example 2: Extracting path components\nconst filePath = '/home/user/app/index.js';\nconsole.log('Basename:', path.basename(filePath)); // Expected: index.js\nconsole.log('Dirname:', path.dirname(filePath));   // Expected: /home/user/app\nconsole.log('Extname:', path.extname(filePath));   // Expected: .js\n\n// Example 3: Resolving relative paths\nconst from = '/data/files';\nconst to = '../../temp/log.txt';\nconst resolvedPath = path.resolve(from, to);\nconsole.log('Resolved path:', resolvedPath); // Expected: /temp/log.txt (simplified for example)\n\n// Example 4: Normalizing a path\nconst uglyPath = '/foo//bar/./baz/../qux';\nconsole.log('Normalized path:', path.normalize(uglyPath)); // Expected: /foo/bar/qux","lang":"javascript","description":"Demonstrates core path operations like joining, extracting components, resolving, and normalizing paths, mimicking the Node.js `path` module API in a browser environment."},"warnings":[{"fix":"Ensure all arguments passed to `path-browserify` methods are of type string. Validate input types before calling path functions.","message":"Starting 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.","severity":"breaking","affected_versions":">=1.0.0"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=0.0.1"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.0.1"},{"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.","message":"`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.","severity":"gotcha","affected_versions":">=0.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"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.","cause":"A `path-browserify` method was called with one or more arguments that were not strings, which is not permitted since v1.0.0.","error":"TypeError: Path must be a string. Received type [number|object|boolean]"},{"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.","cause":"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.","error":"TypeError: Cannot read properties of undefined (reading 'join') or TypeError: path.win32 is not a function"}],"ecosystem":"npm"}