Skip to content

Title: Unable to import subpath exports with @t3-oss/env-core in Turborepo monorepo #374

@Hariharan10202

Description

@Hariharan10202

Hi, I’m using @t3-oss/env-core inside a Turborepo monorepo with multiple workspaces.

I have a package @workspace/env with the following package.json exports setup:

{
"name": "@workspace/env",
"type": "module",
"main": "./dist/server.js",
"types": "./dist/server.d.ts",
"exports": {
".": {
"types": "./dist/server.d.ts",
"default": "./dist/server.js"
},
"./client": {
"types": "./dist/client.d.ts",
"default": "./dist/client.js"
},
"./server": {
"types": "./dist/server.d.ts",
"default": "./dist/server.js"
}
}
}

{
"name": "@workspace/env",
"type": "module",
"main": "./dist/env.js",
"exports": {
".": {
"types": "./dist/env.d.ts",
"require": "./dist/env.js",
"default": "./dist/env.js"
}
},
"scripts": {
"build": "tsc",
"dev": "tsc --watch"
},
"dependencies": {
"@t3-oss/env-core": "^0.13.8",
"zod": "^3.25.76",
"@workspace/typescript-config": "workspace:*"
}
}

When I try to import it from another workspace like:

import { env } from "@workspace/env/server";

I get an error in TypeScript:

Cannot find module '@workspace/env/server' or its corresponding type declarations.

Image

However, import { env } from "@workspace/env" works fine.

What I’ve tried:

Ensured dist/server.js and dist/server.d.ts exist after build.

Checked exports paths match the dist folder structure.

Tried clearing node_modules and rebuilding.

Tried with moduleResolution: bundler and node16 in tsconfig.

Questions:

How do I import in both client and server in a monorepo setup?

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