Skip to content

fix(migrate,cli): import from @prisma/internals's public entry, not its src/ - #29836

Merged
aqrln merged 1 commit into
prisma:v7from
santichausis:fix/internals-completion-values-import
Jul 29, 2026
Merged

fix(migrate,cli): import from @prisma/internals's public entry, not its src/#29836
aqrln merged 1 commit into
prisma:v7from
santichausis:fix/internals-completion-values-import

Conversation

@santichausis

@santichausis santichausis commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Description

@prisma/migrate 7.9.0 fails immediately on require/import with MODULE_NOT_FOUND, before any of its APIs can be used:

Error: Cannot find module '@prisma/internals/src/cli/completion-values'
Require stack:
- node_modules/@prisma/migrate/dist/chunk-WA2SOLDQ.js
- node_modules/@prisma/migrate/dist/index.js

The tab-completion files added in #28351 (*-completion.ts in packages/migrate and packages/cli, plus a couple of related command files) import types and values from deep @prisma/internals/src/... paths — source paths that only resolve inside the monorepo via workspace symlinks. The published @prisma/internals package ships dist/, not src/, so this breaks as soon as @prisma/migrate/@prisma/cli are installed from npm as independent packages, which is exactly what the published prisma CLI does.

I found this affects 4 distinct deep-import paths across 27 files, not just the one path in the original report:

  • @prisma/internals/src/cli/completion-values
  • @prisma/internals/src/cli/types
  • @prisma/internals/src/cli/utils
  • @prisma/internals/src/cli/Help
  • @prisma/internals/src/utils/validatePrismaConfigWithDatasource

All of these are already re-exported from @prisma/internals's public entry (packages/internals/src/index.ts), so this switches every occurrence to import from '@prisma/internals' directly — matching how the rest of the codebase already imports from that package (e.g. DbCommand.ts, Format.ts).

Closes #29772

Test plan

  • Reproduced the exact failure from the issue: built packages/migrate and confirmed require('./dist/index.js') failed with MODULE_NOT_FOUND before the fix, and loads successfully (31 exports) after it.
  • pnpm run test completion in packages/cli — 5/5 passing.
  • pnpm run test DbCommand MigrateCommand in packages/migrate — 8/8 passing.
  • eslint on all changed files — no errors (some files ended up with the value and type imports as two separate import/import type statements from @prisma/internals, which eslint --fix normalizes and the project's lint config accepts).
  • Confirmed via grep that no @prisma/internals/src/... import remains anywhere in the codebase.

Summary by CodeRabbit

  • Refactor
    • Standardized CLI completion and migration command imports through the public internals package interface.
    • Preserved all existing command options, completion definitions, and runtime behavior.
  • Compatibility
    • Improved resilience to internal module structure changes without altering the command-line experience.

…ts src/

Several tab-completion files (added in prisma#28351) imported types and
values from @prisma/internals/src/..., a source path that only
resolves inside the monorepo via workspace symlinks. The published
@prisma/internals package ships dist/, not src/, so requiring
@prisma/migrate (or @prisma/cli) from an installed node_modules threw
MODULE_NOT_FOUND before any of their APIs could be used.

@prisma/internals's public entry already re-exports every value and
type these files need, so this switches all of them to import from
'@prisma/internals' directly, matching how the rest of the codebase
already imports from that package.

Closes prisma#29772
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a4c914b9-ef12-4d5b-9749-647f473baeaf

📥 Commits

Reviewing files that changed from the base of the PR and between 277a3f4 and ae38c66.

📒 Files selected for processing (27)
  • packages/cli/src/bootstrap/bootstrap-completion.ts
  • packages/cli/src/completions/Completions.ts
  • packages/cli/src/completions/completion-definitions.ts
  • packages/cli/src/debug-info-completion.ts
  • packages/cli/src/format-completion.ts
  • packages/cli/src/generate-completion.ts
  • packages/cli/src/generate/introspectSql.ts
  • packages/cli/src/init-completion.ts
  • packages/cli/src/mcp/mcp-completion.ts
  • packages/cli/src/platform/platform-completion.ts
  • packages/cli/src/postgres/link/link-completion.ts
  • packages/cli/src/postgres/postgres-completion.ts
  • packages/cli/src/studio-completion.ts
  • packages/cli/src/validate-completion.ts
  • packages/cli/src/version-completion.ts
  • packages/migrate/src/commands/db-command-completion.ts
  • packages/migrate/src/commands/db-execute-completion.ts
  • packages/migrate/src/commands/db-pull-completion.ts
  • packages/migrate/src/commands/db-push-completion.ts
  • packages/migrate/src/commands/db-seed-completion.ts
  • packages/migrate/src/commands/migrate-command-completion.ts
  • packages/migrate/src/commands/migrate-deploy-completion.ts
  • packages/migrate/src/commands/migrate-dev-completion.ts
  • packages/migrate/src/commands/migrate-diff-completion.ts
  • packages/migrate/src/commands/migrate-reset-completion.ts
  • packages/migrate/src/commands/migrate-resolve-completion.ts
  • packages/migrate/src/commands/migrate-status-completion.ts

📝 Walkthrough

Walkthrough

CLI and migrate completion modules now import Prisma internals types and constants through the public @prisma/internals entrypoint instead of deep internal source paths. No command logic or exported completion definitions changed.

Changes

Public internals imports

Layer / File(s) Summary
CLI import rewiring
packages/cli/src/**
CLI completion modules and introspection code now resolve Prisma internals types and completion values through @prisma/internals.
Migrate completion import rewiring
packages/migrate/src/commands/*-completion.ts
Migrate completion commands now import CommandCompletion and completion value constants from @prisma/internals.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: lgtm

Suggested reviewers: amirsa12, aqrln

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: switching Prisma CLI/migrate imports to the public @prisma/internals entrypoint.
Linked Issues check ✅ Passed The changes address #29772 by removing deep @prisma/internals src imports from @prisma/migrate, which fixes the reported MODULE_NOT_FOUND loading failure.
Out of Scope Changes check ✅ Passed The diff stays within the stated scope of replacing internal import paths with public entrypoint imports.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@aqrln aqrln left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, I'm surprised this even built with the production tsconfig.build.json at all, thanks so much

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 29, 2026
@aqrln aqrln modified the milestones: 7.10.0, 7.9.2 Jul 29, 2026
@aqrln
aqrln merged commit e81d601 into prisma:v7 Jul 29, 2026
254 checks passed
aqrln pushed a commit that referenced this pull request Jul 30, 2026
…ew ones (#29842)

Follow-up to #29836, which fixed the deep `@prisma/internals/src/...`
imports that made `@prisma/migrate` 7.9.0 unloadable (#29772).

## The remaining instance

`packages/cli/src/completions/completion-definitions.ts` still reached
into `@prisma/migrate/src/commands/*` — twelve imports of the same
shape. This one never reached a published artifact, because the CLI
bundles migrate rather than requiring it (`packages/cli/build` contains
no `require("@prisma/migrate")`), but it was the last instance in code
that ships.

All twelve symbols are already re-exported from
`packages/migrate/src/index.ts`, and `tsconfig.build.bundle.json` maps
`@prisma/migrate` to `packages/migrate/src`, so the bundler resolves the
same module graph either way. Measured A/B on an identical base:

| | before | after |
|-|-|-|
| `build/completion.js` | 55,184 B | 55,187 B |
| `build/cli.js` | 2,744,937 B | 2,744,948 B |
| `prisma complete -- migrate d` | ~53 ms | ~53 ms |

`build/completion.js` is a separate, deliberately small esbuild entry,
so I checked this before assuming the deep imports were merely untidy
rather than load-bearing for tab-completion startup. They are not —
esbuild tree-shakes migrate's entry down to the same result.

## The guard

A `no-restricted-imports` pattern for `@prisma/*/src/**`, so the next
one is caught at lint time rather than by a user on npm. Verified
against the pre-fix file: it flags all fourteen imports that constituted
the incident.

Two exemptions:

- **Tests** (`*.test.ts`, `*.vitest.ts`, `__tests__/`, `tests/`) — never
published, and nine of them import
`@prisma/get-platform/src/test-utils/*` for helpers the package entry
does not export.
- **`@prisma/*-wasm`** — wasm-pack output, published to npm with `src/`
intact, so a deep import there resolves fine and the rule's rationale
does not apply. Without this the message would give actively wrong
advice for those packages.

The rule covers import declarations only, so `require.resolve` and jest
config strings are untouched: the Wasm asset lookup in
`packages/cli/helpers/build.ts` and the snapshot-serializer paths in the
jest presets keep working.

## Verification

- `pnpm lint` across the repo: exit 0.
- Rule fires on the pre-fix `completion-definitions.ts` (14 errors),
stays silent on a test file with the same import, and stays silent on
`@prisma/prisma-schema-wasm/src/...`.
- `pnpm --filter prisma tsc`: clean. `pnpm --filter prisma test
completion`: 5/5.
- Rebuilt `@prisma/migrate` and `prisma` from scratch: no
`@prisma/*/src/*` anywhere in the output, `require` of migrate returns
31 exports, and `prisma complete -- migrate d` gives the same three
suggestions as before.

## Scope

One import statement, one lint rule, one line of `AGENTS.md`. No
behaviour changes.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved command completion reliability by updating migration command
integrations.

* **Documentation**
* Added guidance for using supported package entry points instead of
internal source paths.

* **Chores**
* Added linting checks to prevent unsupported internal imports, with
appropriate exceptions for tests and specific tooling.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
lh0x00 pushed a commit to lh0x00/prisma that referenced this pull request Aug 9, 2026
…ts src/ (prisma#29836)

## Description

`@prisma/migrate` 7.9.0 fails immediately on `require`/`import` with
`MODULE_NOT_FOUND`, before any of its APIs can be used:

```
Error: Cannot find module '@prisma/internals/src/cli/completion-values'
Require stack:
- node_modules/@prisma/migrate/dist/chunk-WA2SOLDQ.js
- node_modules/@prisma/migrate/dist/index.js
```

The tab-completion files added in prisma#28351 (`*-completion.ts` in
`packages/migrate` and `packages/cli`, plus a couple of related command
files) import types and values from deep `@prisma/internals/src/...`
paths — source paths that only resolve inside the monorepo via workspace
symlinks. The published `@prisma/internals` package ships `dist/`, not
`src/`, so this breaks as soon as `@prisma/migrate`/`@prisma/cli` are
installed from npm as independent packages, which is exactly what the
published `prisma` CLI does.

I found this affects 4 distinct deep-import paths across 27 files, not
just the one path in the original report:
- `@prisma/internals/src/cli/completion-values`
- `@prisma/internals/src/cli/types`
- `@prisma/internals/src/cli/utils`
- `@prisma/internals/src/cli/Help`
- `@prisma/internals/src/utils/validatePrismaConfigWithDatasource`

All of these are already re-exported from `@prisma/internals`'s public
entry (`packages/internals/src/index.ts`), so this switches every
occurrence to import from `'@prisma/internals'` directly — matching how
the rest of the codebase already imports from that package (e.g.
`DbCommand.ts`, `Format.ts`).

Closes prisma#29772

## Test plan

- Reproduced the exact failure from the issue: built `packages/migrate`
and confirmed `require('./dist/index.js')` failed with
`MODULE_NOT_FOUND` before the fix, and loads successfully (31 exports)
after it.
- `pnpm run test completion` in `packages/cli` — 5/5 passing.
- `pnpm run test DbCommand MigrateCommand` in `packages/migrate` — 8/8
passing.
- `eslint` on all changed files — no errors (some files ended up with
the value and type imports as two separate `import`/`import type`
statements from `@prisma/internals`, which `eslint --fix` normalizes and
the project's lint config accepts).
- Confirmed via `grep` that no `@prisma/internals/src/...` import
remains anywhere in the codebase.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Refactor**
* Standardized CLI completion and migration command imports through the
public internals package interface.
* Preserved all existing command options, completion definitions, and
runtime behavior.
* **Compatibility**
* Improved resilience to internal module structure changes without
altering the command-line experience.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
lh0x00 pushed a commit to lh0x00/prisma that referenced this pull request Aug 9, 2026
…ew ones (prisma#29842)

Follow-up to prisma#29836, which fixed the deep `@prisma/internals/src/...`
imports that made `@prisma/migrate` 7.9.0 unloadable (prisma#29772).

## The remaining instance

`packages/cli/src/completions/completion-definitions.ts` still reached
into `@prisma/migrate/src/commands/*` — twelve imports of the same
shape. This one never reached a published artifact, because the CLI
bundles migrate rather than requiring it (`packages/cli/build` contains
no `require("@prisma/migrate")`), but it was the last instance in code
that ships.

All twelve symbols are already re-exported from
`packages/migrate/src/index.ts`, and `tsconfig.build.bundle.json` maps
`@prisma/migrate` to `packages/migrate/src`, so the bundler resolves the
same module graph either way. Measured A/B on an identical base:

| | before | after |
|-|-|-|
| `build/completion.js` | 55,184 B | 55,187 B |
| `build/cli.js` | 2,744,937 B | 2,744,948 B |
| `prisma complete -- migrate d` | ~53 ms | ~53 ms |

`build/completion.js` is a separate, deliberately small esbuild entry,
so I checked this before assuming the deep imports were merely untidy
rather than load-bearing for tab-completion startup. They are not —
esbuild tree-shakes migrate's entry down to the same result.

## The guard

A `no-restricted-imports` pattern for `@prisma/*/src/**`, so the next
one is caught at lint time rather than by a user on npm. Verified
against the pre-fix file: it flags all fourteen imports that constituted
the incident.

Two exemptions:

- **Tests** (`*.test.ts`, `*.vitest.ts`, `__tests__/`, `tests/`) — never
published, and nine of them import
`@prisma/get-platform/src/test-utils/*` for helpers the package entry
does not export.
- **`@prisma/*-wasm`** — wasm-pack output, published to npm with `src/`
intact, so a deep import there resolves fine and the rule's rationale
does not apply. Without this the message would give actively wrong
advice for those packages.

The rule covers import declarations only, so `require.resolve` and jest
config strings are untouched: the Wasm asset lookup in
`packages/cli/helpers/build.ts` and the snapshot-serializer paths in the
jest presets keep working.

## Verification

- `pnpm lint` across the repo: exit 0.
- Rule fires on the pre-fix `completion-definitions.ts` (14 errors),
stays silent on a test file with the same import, and stays silent on
`@prisma/prisma-schema-wasm/src/...`.
- `pnpm --filter prisma tsc`: clean. `pnpm --filter prisma test
completion`: 5/5.
- Rebuilt `@prisma/migrate` and `prisma` from scratch: no
`@prisma/*/src/*` anywhere in the output, `require` of migrate returns
31 exports, and `prisma complete -- migrate d` gives the same three
suggestions as before.

## Scope

One import statement, one lint rule, one line of `AGENTS.md`. No
behaviour changes.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

## Summary by CodeRabbit

* **Bug Fixes**
* Improved command completion reliability by updating migration command
integrations.

* **Documentation**
* Added guidance for using supported package entry points instead of
internal source paths.

* **Chores**
* Added linting checks to prevent unsupported internal imports, with
appropriate exceptions for tests and specific tooling.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants