Reputation: 13
Using this library: https://env.t3.gg/docs/nextjs to build env validator in nextjs. I am getting following error on "yarn dev": TS2307: Cannot find module '../../env.mjs' or its corresponding type declarations.
I can successfully run the app, but the error shows up everytime when I start the server. Not sure if this is serious.
**env.mjs file: **
// @ts-check
import { createEnv } from '@t3-oss/env-nextjs';
import { z } from 'zod';
export const env = createEnv({
/*
* Serverside Environment variables, not available on the client.
* Will throw if you access these variables on the client.
*/
server: {
API_URL: z.string(),
NODE_ENV: z.enum(['development', 'test', 'production']),
},
/*
* Environment variables available on the client (and server).
*
* 💡 You'll get type errors if these are not prefixed with NEXT_PUBLIC_.
*/
client: {
NEXT_PUBLIC_ENV: z.enum(['development', 'test', 'production']),
NEXT_PUBLIC_API_URL: z.string(),
},
/*
* Due to how Next.js bundles environment variables on Edge and Client,
* we need to manually destructure them to make sure all are included in bundle.
*
* 💡 You'll get type errors if not all variables from `server` & `client` are included here.
*/
runtimeEnv: {
API_URL: process.env.API_URL,
NODE_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_ENV: process.env.NODE_ENV,
NEXT_PUBLIC_API_URL: process.env.API_URL,
},
});
tsconfig.json
{
"compilerOptions": {
"target": "es5",
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"checkJs": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"noUncheckedIndexedAccess": true
"baseUrl": ".",
"paths": {
"@root/*": [
"src/*"
]
},
"allowJs": true,
"moduleResolution": "node"
},
"include": [
"next.config.mjs",
"next-env.d.ts",
".next/types/**/*.ts",
"**/*.ts",
"**/*.tsx"
],
"exclude": ["node_modules"]
}
package.json
{
"dependencies": {
"@acme/core": "0.0.0",
"@acme/db": "0.0.0",
"@prisma/client": "4.15.0",
"@t3-oss/env-nextjs": "^0.4.0",
"@tanstack/react-query": "^4.29.12",
"@trpc/client": "^10.28.2",
"@trpc/next": "^10.28.2",
"@trpc/react-query": "^10.28.2",
"@trpc/server": "10.28.2",
"clsx": "1.2.1",
"daisyui": "3.0.0",
"i18next": "22.5.0",
"next": "13.4.4",
"next-i18next": "13.2.2",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "7.44.2",
"react-i18next": "^12.3.1",
"react-query": "3.39.3",
"superjson": "1.12.3",
"zod": "3.21.4"
},
"devDependencies": {
"@acme/tsconfig": "0.0.0",
"@axe-core/react": "4.7.1",
"@types/node": "20.2.5",
"@types/react": "18.2.7",
"@types/react-dom": "18.2.4",
"autoprefixer": "10.4.14",
"eslint": "8.41.0",
"eslint-config-acme": "0.0.0",
"eslint-plugin-tailwindcss": "3.12.1",
"i18next-typescript": "0.1.0",
"postcss": "8.4.24",
"prettier": "2.8.8",
"prettier-plugin-tailwindcss": "0.3.0",
"tailwindcss": "3.3.2",
"typescript": "5.0.4"
},
}
Upvotes: 1
Views: 211