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.
ActionArg
✓ import { ActionArg } from 'alter-firestore/types/command'
✗ import { ActionArg } from 'alter-firestore'
ActionArg is not exported from the main entry; must use 'alter-firestore/types/command' subpath.
MigrateOptions
✓ import { MigrateOptions } from 'alter-firestore/types/options'
✗ import { MigrateOptions } from 'alter-firestore'
Options types are in the 'types/options' subpath.
require('alter-firestore')
✓ import ... from 'alter-firestore'
✗ const alter = require('alter-firestore')
This package is Pure ESM and cannot be used with CommonJS require(). Package.json must contain 'type': 'module'.
Setup and create a basic migration file that creates a document (up) and deletes it (down), then run against the Firestore emulator.
// Set package.json type to module
// package.json: { "type": "module" }
// Install
// npm i alter-firestore
// Install ts-node for TypeScript execution
// npm i -D ts-node
// Create .alfsrc.js
export default {
emulator: {
options: { projectId: 'demo-project' },
ports: { firestore: '8080' },
},
credentialPaths: { staging: './staging-key.json' },
migrations: { collectionName: 'migrations', directoryPath: 'migrations' },
};
// Create a migration file: migrations/001_create_users.ts
import { ActionArg } from 'alter-firestore/types/command';
import { MigrateOptions } from 'alter-firestore/types/options';
export const up = async ({ firestore }: ActionArg<MigrateOptions>) => {
return firestore.create('users', 'user1', { name: 'Alice' });
};
export const down = async ({ firestore }: ActionArg<MigrateOptions>) => {
const ref = firestore.doc('users/user1');
return firestore.recursiveDelete('users', ref);
};
// Run migration against emulator
// npm run alfs -- migrate
// or: node --loader ts-node/esm node_modules/.bin/alfs migrate
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module
Package is Pure ESM but loaded with require() in a CommonJS context.
fixAdd 'type': 'module' to package.json or dynamically import().
TypeError: Cannot read properties of undefined (reading '…')
.alfsrc.js is missing or incorrectly configured, or a required credential path is not set.
fixEnsure .alfsrc.js exists with proper fields for your environment (emulator or credentialPaths).
Audit
Dependencies
firebase-adminrequiredUsed to interact with Firestore (getDoc, create, recursiveDelete)
ts-nodeoptionalRequired to execute TypeScript migration/alter files via ts-node-esm