{"record":{"id":"58c8a6508e671fa2","repo":"microsoft/playwright","slug":"path-is-not-available-in-the-browser","errorCode":null,"errorMessage":"path is not available in the browser","messagePattern":"path is not available in the browser","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/playwright-client/src/nodeStubs/path.ts","lineNumber":18,"sourceCode":"/**\n * Copyright (c) Microsoft Corporation.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nfunction notAvailable(): never {\n  throw new Error('path is not available in the browser');\n}\n\nexport const sep = '/';\nexport const dirname: any = notAvailable;\nexport const basename: any = notAvailable;\nexport const resolve: any = notAvailable;\nexport const join: any = notAvailable;\nexport const relative: any = notAvailable;\nexport const isAbsolute: any = notAvailable;\n\nexport default { sep, dirname, basename, resolve, join, relative, isAbsolute };\n","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/microsoft/playwright/blob/c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6/packages/playwright-client/src/nodeStubs/path.ts#L1-L30","documentation":"Thrown by the browser-bundle stub of Node's `path` module: calling `path.dirname`, `basename`, `resolve`, `join`, `relative`, or `isAbsolute` invokes `notAvailable()` which throws. Only `path.sep` (`'/'`) is defined; all functional exports throw immediately.","triggerScenarios":"Code resolved to `packages/playwright-client/src/nodeStubs/path.ts` (the browser client bundle) that calls any path utility: `path.join(...)`, `path.resolve(...)`, `path.dirname(...)`, etc.","commonSituations":"Shared path-handling code bundled into the browser client; a dependency that requires `path` at runtime; bundler aliasing `path` to the stub for the browser target.","solutions":["Gate path operations behind a Node-only code path and avoid importing `path` in the browser bundle.","Replace simple join/normalize logic with template strings or a tiny browser-safe helper.","Mark `path` as external for the Node build target so it is not replaced by the stub."],"exampleFix":"// before\nimport path from 'path';\nconst full = path.join(base, file);  // throws in browser bundle\n\n// after\nconst full = typeof window === 'undefined'\n  ? (await import('path')).join(base, file)\n  : `${base}/${file}`;","handlingStrategy":"type-guard","validationCode":"function safePathJoin(...segs: string[]): string {\n  if (typeof window !== 'undefined') return segs.join('/');\n  return require('path').join(...segs);\n}","typeGuard":"function pathAvailable(): boolean {\n  return typeof window === 'undefined' && typeof process !== 'undefined' && !!process.versions?.node;\n}","tryCatchPattern":"try {\n  return path.join(...segs);\n} catch (e) {\n  if (/path is not available in the browser/.test(e.message)) {\n    return seggs.join('/');\n  }\n  throw e;\n}","preventionTips":["Use a tiny browser-safe join helper in shared code.","Externalize `path` for Node targets so the stub is not substituted.","Split path logic into platform-specific modules."],"tags":["browser-bundle","node-stubs","path","environment"],"backgroundTag":null,"analyzedSha":"c8fc3bf8d31542d59b4d4d9eaab1df93ff541dc6","analyzedAt":"2026-08-12T07:26:36.950Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}