Skip to content

contract emit crashes (CLI.UNEXPECTED, ERR_INVALID_ARG_VALUE) with the relative contract path that orm init scaffolds #205

Closed

Description

@ankur-arch

Summary

orm init scaffolds prisma.config.ts with a relative contract path:

orm: ormConfig({
  contract: "./src/prisma/contract.prisma",
  db: { connection: process.env['DATABASE_URL']! },
}),

With that config, contract emit crashes:

CLI.UNEXPECTED: The argument 'filename' must be a file URL object, file URL string, or absolute path
string. Received './src/prisma/package.json'  (ERR_INVALID_ARG_VALUE)

Changing the config to an absolute path (new URL('./src/prisma/contract.prisma', import.meta.url).pathname) makes the same command succeed and emit contract.json/contract.d.ts normally.

Where it breaks

In @prisma/orm-toolchain@8.0.0-rc.2 (dist ref-*.mjs), validateContractDeps does:

const resolve = createRequire(`${projectRoot}/package.json`);

and projectRoot arrives as the relative ./src/prisma derived from the config's contract path, but node:module's createRequire requires an absolute path or file URL. Either the config loader should absolutize contract against the config file's directory before handing it to the toolchain, or the toolchain should resolve projectRoot to an absolute path itself.

Filing here because the repro is entirely through prisma-cli commands and the config loader (cli-engine loadConfig) may be the layer that should absolutize; transfer to the ORM repo if it's purely an orm-toolchain fix.

Repro caveat

Reproduced on macOS / Node 24.11.1 with the rc.4 CLI shell and a locally patched @prisma/cli-engine built from repo HEAD, because the published engine crashes the CLI at startup (#202). I could not verify against a fully published stack for that reason. Today users hit this bug's surface anyway: orm init's final emit step fails with CLI.INIT_EMIT_FAILED due to #202, and once that is fixed, this crash is the next thing the default scaffold + contract emit flow runs into (unless the published engine absolutizes the path where the HEAD engine does not).

Found while validating the docs quickstart end to end (prisma/web#8151).

🤖 Filed with Claude Code on behalf of datta@prisma.io

Activity

  1. ankur-arch commented on Aug 18, 2026

    @ankur-arch
    ContributorAuthor

    Reproduced and fixed. Evidence trail:

    • Repro (today, repo-built CLI at main + published toolchain): orm init --target postgres --authoring psl scaffolds contract: "./src/prisma/contract.prisma"; contract emit then fails with CLI.UNEXPECTED: The argument 'filename' must be a file URL object, file URL string, or absolute path string. Received './src/prisma/package.json' (ERR_INVALID_ARG_VALUE) — after the emit step itself reports ok. Switching the config to an absolute path (new URL(...).pathname) makes the same command succeed, exactly as reported. @prisma/orm-toolchain@8.0.0-rc.3 (published yesterday, what the rc.5 CLI will pin) has a byte-identical validateContractDeps — still broken.
    • Layer verdict: this is purely an orm-toolchain fix. The cli-engine config loader hands sections back opaquely (a ConfigSection validator receives only the raw value — no config-file path), so the engine cannot absolutize a path field it doesn't know exists; and validateContractDeps is the one place that requires an absolute path (createRequire), while every other consumer of the relative path (the emit step, projectImportRoot) already resolves it against cwd.
    • Fix: fix(cli): contract emit accepts the relative contract path orm init scaffolds orm#30061 — the project root resolves against the working directory before createRequire sees it, with a regression test. Verified end to end: the default orm init scaffold + contract emit completes (ok: true, both artifacts written) with that build overlaid, where rc.2/rc.3 crash.

    Leaving this open until the fix ships in a published @prisma/orm-toolchain that the CLI pins (it rides the next toolchain release + the CLI's automated product-version bump).

  2. ankur-arch commented on Aug 18, 2026

    @ankur-arch
    ContributorAuthor

    Update now that prisma@next = 8.0.0-rc.5 works (#202 closed): the repro caveat in the issue body no longer applies — this reproduces on a fully published stack, no repo builds involved:

    # fresh project: npm install prisma@next @prisma/orm-postgres dotenv
    # prisma.config.ts exactly as orm init scaffolds it (contract: "./src/prisma/contract.prisma")
    $ ./node_modules/.bin/prisma contract emit
    CLI.UNEXPECTED: The argument 'filename' must be a file URL object, file URL string, or absolute
    path string. Received './src/prisma/package.json'  (ERR_INVALID_ARG_VALUE)
    

    rc.5 pins @prisma/orm-toolchain@8.0.0-rc.3, whose validateContractDeps is unchanged. Fix remains prisma/orm#30061 (all checks green, awaiting review); it reaches users via the next toolchain release + the CLI's automated product-version bump.

  3. ankur-arch commented on Aug 18, 2026

    @ankur-arch
    ContributorAuthor

    Fix status update: the toolchain fix landed on prisma/prisma main via prisma/orm#30064 (merged today, same resolve-before-createRequire change with a regression test; my prisma/orm#30061 is closed as superseded by it). This issue closes once a published @prisma/orm-toolchain release carries it and the CLI's automated product-version bump picks that release up.

  4. wmadden-electric commented on Sep 27, 2026

    @wmadden-electric
    Contributor

    Fixed by prisma/orm#30064, which ships in @prisma/orm-toolchain@8.0.0-rc.12 (in prisma@8.0.0-rc.17). Verified 2026-09-27 against the published rc.17: prisma orm init --target postgres --authoring psl scaffolds contract: "./src/prisma/contract.prisma", and prisma contract emit succeeds with that relative path, both from the project root and from subdirectories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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