Registry / storage / file-system-access

file-system-access

JSON →
library1.0.4jsnpmunverified

A TypeScript ponyfill implementing the WICG File System Access specification with pluggable storage adapters (IndexedDB, Cache API, Node fs, Deno, in-memory). Version 1.0.4, active development. Falls back to native browser API when available, with strict error handling and modern ESM support. Includes ponyfills for picker methods and writable file streams. Fully typed, supports tree-shaking.

npm install file-system-access
INSTALL
IMPORT
SIG · FILE-SYSTEM-ACCESS
F
file-system-access
storagejavascriptv1.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

getOriginPrivateDirectory
import { getOriginPrivateDirectory } from 'file-system-access'
const { getOriginPrivateDirectory } = require('file-system-access')
ESM-only; CommonJS require will fail with ERR_REQUIRE_ESM. Always use ES import.
indexedDbAdapter
import indexedDbAdapter from 'file-system-access/lib/adapters/indexeddb.js'
import { indexedDbAdapter } from 'file-system-access'
Adapters are default exports from their respective module paths, not re-exported from the main entry.
showDirectoryPicker
import { showDirectoryPicker } from 'file-system-access'
import showDirectoryPicker from 'file-system-access'
Picker functions are named exports, not default.

Demonstrates using getOriginPrivateDirectory with IndexedDB adapter to create and write a file, and using showDirectoryPicker as a ponyfill.

import { getOriginPrivateDirectory, showDirectoryPicker } from 'file-system-access'; import indexedDbAdapter from 'file-system-access/lib/adapters/indexeddb.js'; async function main() { // Use IndexedDB adapter to get a sandboxed directory const dirHandle = await getOriginPrivateDirectory(indexedDbAdapter); // Create a new file and write to it const fileHandle = await dirHandle.getFileHandle('hello.txt', { create: true }); const writable = await fileHandle.createWritable(); await writable.write('Hello, World!'); await writable.close(); console.log('File written successfully'); // Use native picker (if available) or fallback try { const selectedDir = await showDirectoryPicker(); console.log('Selected directory:', selectedDir.name); } catch (err) { console.error('Picker failed:', err); } } main();
Debug
Known issues
breakingNative File System Access API is only available in secure contexts (HTTPS) and supported in Chromium-based browsers (Chrome 86+, Edge 86+). Safari 15.2+ has partial support. Firefox does not implement it.
fix
Use this ponyfill to provide a consistent API across browsers. Check browser support at https://caniuse.com/native-filesystem-api
affects: *
breakingThe 'sandbox' adapter is deprecated and uses the obsolete requestFileSystem API, only available in Chromium-based browsers.
fix
Use 'indexeddb' or 'memory' adapter instead of 'sandbox'. Remove any usage of file-system-access/lib/adapters/sandbox.js
affects: >=1.0.0
gotchaIn Node.js, the 'node' adapter requires Node 14.8+ for ESM support. The adapter uses fs.promises and may not work with older Node versions.
fix
Ensure Node.js version is >=14.8. If using CommonJS, consider dynamic import().
affects: >=1.0.0
gotchaWhen using the 'cache' adapter with the Cache API, stored files are subject to browser cache eviction policies and may be removed without warning.
fix
Use 'indexeddb' adapter for persistent storage if data durability is required.
affects: >=1.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/file-system-access/lib/es2018.js from /path/to/project/index.js not supported. Instead change the require of /path/to/node_modules/file-system-access/lib/es2018.js to a dynamic import() which is available in all CommonJS modules.
Attempting to require() an ESM-only package from CommonJS.
fix
Use dynamic import: const { getOriginPrivateDirectory } = await import('file-system-access'); or convert your project to ESM.
TypeError: adapter is not a function
Passing an adapter import directly to getOriginPrivateDirectory without calling the default export function.
fix
Adapter must be called to produce the adapter instance: const adapter = indexedDbAdapter(); const dir = await getOriginPrivateDirectory(adapter);
DOMException: Failed to execute 'showDirectoryPicker' on 'Window': The request is not allowed by the user agent or the platform in the current context.
showDirectoryPicker requires a secure context (HTTPS) and user gesture (e.g., click event).
fix
Ensure the page is served over HTTPS and call the function within a user-initiated event handler, such as a button click.
TypeError: Cannot read properties of undefined (reading 'length')
Using the 'node' adapter without providing a path argument, or providing an invalid path.
fix
Call getOriginPrivateDirectory(nodeAdapter, '/path/to/directory') with a valid directory path.
Upgrade
Version history
1.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
36
Resources
file-system-access — npm install file-system-access · libregistry