Skip to content

hub:db:schema:extend prefers .ts over .mjs, breaks build when buildDir is inside node_modules #129

@onmax

Description

@onmax

Bug

When buildDir is not explicitly set in nuxt.config.ts and a .nuxt/ directory exists from dev, Nuxt Kit redirects buildDir to node_modules/.cache/nuxt/.nuxt during production builds (source).

The hub:db:schema:extend hook in nuxt-better-auth prefers the .ts path over .mjs:

// module.mjs:277-286
nuxtWithHubHooks.hook("hub:db:schema:extend", ({ paths, dialect: hookDialect }) => {
  const tsPath = join(nuxt.options.buildDir, "better-auth", `schema.${hookDialect}.ts`);
  const mjsPath = join(nuxt.options.buildDir, "better-auth", `schema.${hookDialect}.mjs`);
  if (existsSync(tsPath)) {
    paths.unshift(tsPath);  // prefers .ts
    return;
  }
  if (existsSync(mjsPath))
    paths.unshift(mjsPath);
});

Since the .ts file ends up inside node_modules/, Node.js type stripping refuses to process it:

ERROR  Stripping types is currently unsupported for files under node_modules,
for "node_modules/.cache/nuxt/.nuxt/better-auth/schema.sqlite.ts"

Fix

Prefer .mjs over .ts in the hook — the generated schema code is pure JS anyway, so .mjs works fine.

Workaround

Set buildDir: '.nuxt' explicitly in nuxt.config.ts to prevent the redirect.

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