Skip to content

ESM import resolution fails: missing .js extensions in dist/index.js #11

@L4Ph

Description

@L4Ph

Environment

  • better-auth-firestore: 1.1.2
  • better-auth: 1.4.19
  • Runtime: Node.js (via Vite dev server / @hono/vite-dev-server)
  • Module type: ESM ("type": "module")

Problem

When importing better-auth-firestore in a strict ESM environment (Node.js with "type": "module"), the following error occurs:

Cannot find module '.../better-auth-firestore/dist/firebase-adapter'
imported from .../better-auth-firestore/dist/index.js

Root Cause

dist/index.js uses bare relative imports without .js extensions:

// dist/index.js (current — broken in ESM)
export { firestoreAdapter } from "./firebase-adapter";
export { initFirestore } from "./firestore";
export { generateIndexSetupUrl, getIndexConfig } from "./setup";
export * from "./types";

Node.js ESM requires explicit file extensions for relative imports. Without .js, resolution fails.

The same issue exists in dist/firebase-adapter.js:

import { initFirestore } from "./firestore"; // should be "./firestore.js"

Fix

Add .js extensions to all relative imports in the dist/ files:

// dist/index.js (fixed)
export { firestoreAdapter } from "./firebase-adapter.js";
export { initFirestore } from "./firestore.js";
export { generateIndexSetupUrl, getIndexConfig } from "./setup.js";
export * from "./types.js";
// dist/firebase-adapter.js (fixed)
import { initFirestore } from "./firestore.js";

This is typically fixed in the library's tsconfig.json by setting moduleResolution to "node16" or "bundler", which causes TypeScript to emit explicit .js extensions in output files. Alternatively, configure the bundler (tsup, esbuild, etc.) to preserve or add extensions on relative imports.

Workaround

Applied a pnpm patch to add .js extensions manually until this is fixed upstream.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions