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();
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.
fixUse 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.
fixAdapter 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).
fixEnsure 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.
fixCall getOriginPrivateDirectory(nodeAdapter, '/path/to/directory') with a valid directory path.
Audit
Dependencies
No dependency data recorded yet.