Skip to content

tsx fails to load @credo-ts/drizzle-storage: import.meta.dirname is undefined #2579

@Patrik-Stas

Description

@Patrik-Stas

After upgrading from alpha version to recent release, I started to have problem with running the code using tsx.

Reproduction is as simple as running this

import { DrizzleStorageModule } from '@credo-ts/drizzle-storage';

const drizzleModule = new DrizzleStorageModule({
  // @ts-ignore
  database: undefined,
  bundles: [],
});

with tsx ( I've created repo https://github.com/Patrik-Stas/tsx-credo-06-reproduction/tree/main so you can just checkout and run pnpm run test )
This produces output

pnpm run test

> [email protected] test /Users/patrik/dev/foobar/project/tsx-credo-06-reproduction
> tsx src/index.ts

/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/@[email protected]_@[email protected]._de4f30d7974941e97c44732dbbbc5bba/node_modules/@credo-ts/drizzle-storage/build/util.mjs:4
const addSchemaExtension = (path) => dirname.endsWith("/src") ? `${path}.ts` : `${path}.mjs`;
                                             ^

TypeError: Cannot read properties of undefined (reading 'endsWith')
    at addSchemaExtension (/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/@[email protected]_@[email protected]._de4f30d7974941e97c44732dbbbc5bba/node_modules/@credo-ts/drizzle-storage/build/util.mjs:4:46)
    at bundleMigrationDefinition (/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/@[email protected]_@[email protected]._de4f30d7974941e97c44732dbbbc5bba/node_modules/@credo-ts/drizzle-storage/build/util.mjs:7:15)
    at <anonymous> (/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/@[email protected]_@[email protected]._de4f30d7974941e97c44732dbbbc5bba/node_modules/@credo-ts/drizzle-storage/build/core/bundle.mjs:26:14)
    at Object.<anonymous> (/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/@[email protected]_@[email protected]._de4f30d7974941e97c44732dbbbc5bba/node_modules/@credo-ts/drizzle-storage/build/core/bundle.mjs:27:1)
    at Module._compile (node:internal/modules/cjs/loader:1546:14)
    at Object.transformer (/Users/patrik/dev/foobar/project/tsx-credo-06-reproduction/node_modules/.pnpm/[email protected]/node_modules/tsx/dist/register-D46fvsV_.cjs:3:1104)
    at Module.load (node:internal/modules/cjs/loader:1318:32)
    at Function._load (node:internal/modules/cjs/loader:1128:12)
    at TracingChannel.traceSync (node:diagnostics_channel:315:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:218:24)

Node.js v22.11.0

The problem refers to file packages/drizzle-storage/src/util.ts specifically line
export const dirname = import.meta.dirname that was added on 11th of October.

The issue is probably related to following PR on 27th November
#2539

based on which alpha versions work with/without issue

0.6.0-alpha-20251117150036 OK
0.6.0-alpha-20251118085559 OK
0.6.0-alpha-20251121023030 OK
0.6.0-alpha-20251127043254 OK

0.6.0-alpha-20251128133214 XX

I am not sure if this is actually concern of credo-ts. Maybe just wrong configuration on my end, or expected behavior related exclusive ESM support? Anyway any thoughts appreicated~

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions