Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How t3env works in an nx integrated enviroment monorepo? #270

Open
codersaadi opened this issue Sep 29, 2024 · 0 comments
Open

How t3env works in an nx integrated enviroment monorepo? #270

codersaadi opened this issue Sep 29, 2024 · 0 comments

Comments

@codersaadi
Copy link

codersaadi commented Sep 29, 2024

I am using nx repo with nextjs integrated enviroment , env variables are the concern ,
as t3env does not support node module resolution, so it is a problem.

nx js provides a base.json at the root level with module resolution node for nextjs integrated enviroment

{
  "compileOnSave": false,
  "compilerOptions": {
    "rootDir": ".",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "module": "esnext",
    "lib": ["es2020", "dom"],
    "skipLibCheck": true,
    "skipDefaultLibCheck": true,
    "baseUrl": ".",
    "paths": {
      "@org/shared": ["libs/shared/src/index.ts"],
      "@org/shared/*": ["libs/shared/src/*"],
      "@org/shared/env": ["libs/shared/src/env.ts"],
      "@org/shared/email": ["libs/shared/src/email.ts"],
      "@org/shared/lib/*": ["libs/shared/src/lib/*"],
      "@org/shared/server": ["libs/shared/src/server.ts"],
      "@org/utils": ["libs/utils/src/index.ts"],
      "@web/*": ["apps/web/src/*"]
    }
  },
  "exclude": ["node_modules", "tmp"]
}

Cannot find module '@t3-oss/env-core' or its corresponding type declarations.
There are types at '/home/code/Desktop/monorepos/org/node_modules/@t3-oss/env-core/dist/index.d.ts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.ts(2307)

with node 16
The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("@t3-oss/env-core")' call instead.
To convert this file to an ECMAScript module, change its file extension to '.mts', or add the field "type": "module" to '/home/code/Desktop/monorepos/org/libs/shared/package.json'.ts(1479)
module "/home/code/Desktop/monorepos/org/node_modules/.pnpm/@t3-oss[email protected][email protected][email protected]/node_modules/@t3-oss/env-core/dist/index"

should i use core ?

there could be multiple apps like react etc , so i think core should be appropriate , will it work in nextjs the sameway , t3next works ? i have seen
no example of it so far

i have solved it by coping the code of t3 core internally

and using it as utility from the utils.
otherwise it was resulting in type issues.

import { createEnv } from './lib/internal-env';
but thats not a very friendly solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant