pnpm workspace package not resolved during TypeScript build (TS2307)
gkuhlmann14
PROOP

3 months ago

Deploying a pnpm monorepo where backend depends on a workspace package. TypeScript fails with TS2307 "Cannot find module" even though the package is built and linked.

Setup:

- pnpm workspace: backend/ depends on packages/api-contract/

- Dependency: "@bizmeetcreator/api-contract": "workspace:*" in backend's package.json

- Root Directory: unset (following advice from this thread

- Build Command: pnpm --filter bizmeetcreator-backend... build

TypeScript config:

```json

{

"compilerOptions": {

"module": "ES2022",

"moduleResolution": "bundler",

"target": "ES2022"

}

}

```

We use moduleResolution: "bundler" because:

- It properly respects package.json exports field (our api-contract package uses conditional exports)

- It's the recommended setting for modern ESM + bundler workflows (we use tsup)

- "node" and "node16" have quirks with workspace packages that use exports

Error:

```

src/system/business/cityResolution.ts(21,8): error TS2307: Cannot find module '@bizmeetcreator/api-contract/v1/business' or its corresponding type declarations.

```

The api-contract package.json exports:

```json

{

"exports": {

"./v1/business": {

"types": "./dist/v1/business/index.d.ts",

"default": "./dist/v1/business/index.js"

}

}

}

```

What I've tried:

1. Using prebuild script to build api-contract first

2. Removing explicit tsconfig path mappings (letting pnpm resolve via node_modules)

3. Using pnpm --filter backend... build (with ... to build dependencies first)

Works locally - the same command succeeds on my machine where pnpm workspace symlinks are intact.

Question:

Are pnpm workspace symlinks preserved after pnpm install on Railway? With moduleResolution: "bundler", TypeScript needs to follow the symlink and read the package.json exports to resolve @bizmeetcreator/api-contract/v1/businesspackages/api-contract/dist/v1/business/index.d.ts.

---

$10 Bounty

1 Replies

3 months ago

This thread has been marked as public for community involvement, as it does not contain any sensitive or personal information. Any further activity in this thread will be visible to everyone.

Status changed to Open itsrems 3 months ago


dardameiz
PRO

3 months ago

hey, try this one:

1.two stage build command:

pnpm --filter @bizmeetcreator/api-contract build && pnpm --filter bizmeetcreator-backend build

2. or you can try to add to backend (tsconfig.json):

{

"compilerOptions": {

"preserveSymlinks": true

}

}

short answer to you question is yes, pnpm symlinks are preserved on Railway. The issue is likely build order timing - your api-contract dist files don't exist when TypeScript tries to resolve them


Loading...