t3-oss / t3-env

https://env.t3.gg
MIT License
2.67k stars 86 forks source link

Cannot find module '@t3-oss/env-core' or its corresponding type declarations. #245

Closed ericmesmo closed 2 months ago

ericmesmo commented 3 months ago

I'm using turborepo and in it I have a package to get the application's variables, whether front or back.

When using the @repo/env-config package within the api application, which uses nestjs, an error is returned: Cannot find module '@t3-oss/env-core' or its corresponding type declarations.

I couldn't find a solution, could someone help me?

image

A repo to reproduce the error: https://github.com/ericmesmo/reproducible

kon-pas commented 2 months ago

Resolved here: #189

@ericmesmo In your case, to use a distinct tsconfig in a package, it has to go through the dev or build step.

First, configure your dist directory in env-config/tsconfig.json:

{
  "extends": "@repo/typescript-config/base.json",
  "include": ["index.ts"],
+ "exclude": ["dist"],
+ "compilerOptions": {
+   "outDir": "dist"
+ },
}

Then, update endpoints and scripts in env-config/package.json:

{
  "name": "@repo/env-config",
  "version": "1.0.0",
  "description": "",
  "private": true,
- "main": "index.ts",
+ "main": "dist/index.js",
- "types": "index.ts",
+ "types": "dist/index.d.ts",
  "type": "module",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
+   "build": "tsc",
+   "dev": "tsc --watch"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "@t3-oss/env-core": "^0.10.1",
    "ts-node": "^10.9.1",
    "tsup": "^8.1.0",
    "typescript": "^5.4.5",
    "zod": "^3.23.8"
  },
  "devDependencies": {
    "@types/node": "^20.14.2",
    "typescript": "^5.4.5",
    "@repo/typescript-config": "workspace:*"
  }
}

Now you can build your apps that use the env-config package:

pnpm build
juliusmarminge commented 2 months ago

I couldn't find a solution, could someone help me?

The error explains how to solve this: CleanShot 2024-07-22 at 10 06 09

This is also mentioned in the readme of this repo and in the docs