{"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,"search_vec":"'10.3.0':68 'api':70,128,149 'approach':131 'behavior':73 'browser':5,12,34,144,151 'browser-compat':11 'browserifi':8,47,87,152 'bugfix':119 'bundler':45 'choic':136 'common':37 'compat':13 'consist':72 'context':145 'core':124 'current':61 'design':20 'direct':55,120 'driven':104 'elimin':51 'ensur':71 'environ':23 'featur':117 'focus':114 'full':82 'function':91,142 'implement':14,89 'includ':95 'instal':56 'introduc':147 'javascript':44,150 'like':46 'maintain':126 'make':132 'mani':58 'mirror':65 'modul':3,19,28,84,111 'nativ':26 'need':53,139 'new':148 'node.js':1,17,27,67,83,109,123,140 'often':50 'oper':79 'pariti':129 'path':2,7,18,69,78,86,110,141,153 'path-browserifi':6,85 'path.win32':99 'polyfil':42 'port':116 'posix':76,90 'posix-styl':75 'primarili':21 'project':59,138 'provid':9 'releas':101 'reliabl':135 'specif':98 'stabl':62 'strict':127 'style':77 'transpar':41 'typic':103 'unavail':30 'unlik':80 'updat':106 'use':38 'util':100 'v1.0.1':64 'version':63 'web':33 'webpack':49 'window':97 'windows-specif':96 'without':146","created_at":"2026-04-19T13:38:27.791154+00:00","updated_at":"2026-04-19T13:38:27.791154+00:00","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","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/browserify/path-browserify","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/path-browserify","openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-17","next_check":"2026-07-18","install_tag":null}}