nitrojs / nitrojs/nitro

Module Path Resolution Error When Using Monorepo + Nitro + Prisma

Open
#3,403 16 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug externals v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

Linux x64, NodeJS v22.15.0

Reproduction

I've created a minimal reproduction repo using pnpm monorepo + Nitro + Prisma, which reliably reproduces the bug on my machine (Linux x64, NodeJS v22.15.0):

https://github.com/MagmaBlock/nitro-prisma-monorepo-debug

Describe the bug

In a pnpm monorepo environment, Nitro appears to have issues resolving module paths when importing local workspace packages.

The specific symptom is that in .nitro/dev/index.mjs (or .nuxt/dev/index.mjs), incorrect relative paths are being generated for the imported Prisma client:

import { PrismaClient } from '../../../../../../../../../packages/database/generated/client';

This path contains an excessive number of ../, clearly going beyond the valid directory structure. In VSCode, this path also cannot be clicked through or resolved.

Meanwhile, all other imports are using absolute paths like this:

import consola from 'file:///home/magma/projects/nitro-prisma-monorepo-debug/node_modules/.pnpm/consola@3.4.2/node_modules/consola/dist/index.mjs';
import { ErrorParser } from 'file:///home/magma/projects/nitro-prisma-monorepo-debug/node_modules/.pnpm/youch-core@0.3.2/node_modules/youch-core/build/index.js';
import { Youch } from 'file:///home/magma/projects/nitro-prisma-monorepo-debug/node_modules/.pnpm/youch@4.1.0-beta.8/node_modules/youch/build/index.js';
import { SourceMapConsumer } from 'file:///home/magma/projects/nitro-prisma-monorepo-debug/node_modules/.pnpm/source-map@0.7.4/node_modules/source-map/source-map.js';
import { Server } from 'node:http';

Only the Prisma import uses a relative path — all others use absolute file URLs. This leads to runtime errors when trying to use the Prisma client inside Nitro:

Cannot find module '/packages/database/generated/client' imported from /home/magma/projects/nitro-prisma-monorepo-debug/apps/nitro/.nitro/dev/index.mjs

And the build also fails as a result.

Additional context

No response

Logs

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal reproduction repository linked in the issue and run the pnpm monorepo with Nitro and Prisma on Linux. Inspect the generated .nitro/dev/index.mjs or .nuxt/dev/index.mjs, focusing on the Prisma client import and its path compared with the other imports. Done means the Prisma client resolves correctly and the Nitro build and runtime no longer fail.

Written by the indexing model from the issue text.

Assessment

Tech stack
nodejs, typescript
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.