{"record":{"id":"ce967d834c007c2e","repo":"parcel-bundler/parcel","slug":"nodefs-isn-t-available-in-the-browser","errorCode":null,"errorMessage":"NodeFS isn't available in the browser","messagePattern":"NodeFS isn't available in the browser","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"critical","filePath":"packages/core/fs/src/NodeFS.browser.js","lineNumber":7,"sourceCode":"// @flow\nimport type {FileSystem} from '@parcel/types-internal';\n\n// $FlowFixMe[prop-missing] handled by the throwing constructor\nexport class NodeFS implements FileSystem {\n  constructor() {\n    throw new Error(\"NodeFS isn't available in the browser\");\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":10,"githubUrl":"https://github.com/parcel-bundler/parcel/blob/59484858a1a0bcbb71f74088956bb437a2db6505/packages/core/fs/src/NodeFS.browser.js#L1-L10","documentation":"Thrown unconditionally in the constructor of NodeFS when the browser-specific build is loaded. Parcel ships two implementations of NodeFS: one for Node.js (using the real fs module) and one for browsers (NodeFS.browser.js) that throws immediately. This is a compile-time replacement via Parcel's bundler aliases, not a runtime check.","triggerScenarios":"Any code path that instantiates `new NodeFS()` in a browser environment. This happens when a library or Parcel internal module that imports NodeFS is bundled for the browser without proper tree-shaking or conditional loading. The import resolves to NodeFS.browser.js via the module resolver.","commonSituations":"A Parcel plugin is imported into a browser-side preview or playground that doesn't guard the NodeFS import. A test runner configured for jsdom (browser-like) tries to exercise code that depends on NodeFS. A custom bundler config accidentally includes server-only modules in a browser bundle.","solutions":["Ensure NodeFS is only imported in Node.js contexts — use conditional imports or dynamic imports gated by `typeof window === 'undefined'`.","Use MemoryFS or OverlayFS for browser-side virtual filesystem operations instead of NodeFS.","If using a bundler, mark NodeFS as external or provide a browser stub that doesn't throw."],"exampleFix":"// before\nimport {NodeFS} from '@parcel/fs';\nconst fs = new NodeFS(); // throws in browser\n\n// after\nimport {MemoryFS} from '@parcel/fs';\n// or use conditional dynamic import:\n// const {NodeFS} = typeof window === 'undefined' ? require('@parcel/fs') : {NodeFS: null};","handlingStrategy":"validation","validationCode":"// Prevent NodeFS instantiation in browser environments\nfunction createFS() {\n  if (typeof window !== 'undefined' || typeof process === 'undefined') {\n    // Browser environment — use MemoryFS\n    const {MemoryFS} = require('@parcel/fs');\n    return new MemoryFS();\n  }\n  const {NodeFS} = require('@parcel/fs');\n  return new NodeFS();\n}","typeGuard":"// Environment guard\nfunction isBrowser() {\n  return typeof window !== 'undefined' ||\n    (typeof process !== 'undefined' && process.type === 'renderer') ||\n    typeof navigator !== 'undefined' && navigator.userAgent.includes('node') === false;\n}","tryCatchPattern":"try {\n  const fs = new NodeFS();\n} catch (e) {\n  if (e.message.includes(\"isn't available in the browser\")) {\n    const {MemoryFS} = require('@parcel/fs');\n    fs = new MemoryFS();\n  } else {\n    throw e;\n  }\n}","preventionTips":["Use conditional imports gated by environment checks before importing NodeFS.","Configure your bundler to replace NodeFS with a browser-compatible stub.","Prefer MemoryFS or OverlayFS for code that may run in both Node and browser contexts.","Mark server-only modules as external in browser builds."],"tags":["filesystem","nodefs","browser","environment","constructor"],"backgroundTag":null,"analyzedSha":"59484858a1a0bcbb71f74088956bb437a2db6505","analyzedAt":"2026-08-13T04:06:35.925Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}