t3-oss / t3-env

https://env.t3.gg
MIT License
2.72k stars 84 forks source link

help needed for build checking #269

Open sahandsn opened 1 month ago

sahandsn commented 1 month ago

is there any more documentation/tutorials on how can i integrate unjs/jiti for checking env variables at build time with next.config.mjs?

tiavina-mika commented 3 weeks ago

+1

tiavina-mika commented 3 weeks ago

here is an example of how to use it https://github.com/t3-oss/t3-env/tree/main/examples/nextjs

Teekola commented 2 weeks ago

It seems like using jiti with a higher version than in the example (1.21.0) will cause a webpack warning.

Next config file

// next.config.mjs

import createJiti from "jiti";
import { fileURLToPath } from "node:url";

const jiti = createJiti(fileURLToPath(import.meta.url));

// Import env here to validate during build. Using jiti we can import .ts files
jiti("./src/env/server");
jiti("./src/env/client");

Warning that is logged on both locale development and on Vercel. On locale development this is logged even on npm run dev, on Vercel this is during build.

<w> [webpack.cache.PackFileCacheStrategy/webpack.FileSystemInfo] Parsing of /vercel/path0/node_modules/jiti/lib/jiti.mjs for build dependencies failed at 'import(id)'.
<w> Build dependencies behind this expression are ignored and might cause incorrect cache invalidation.

Switching to the older jiti version (1.21.0) made the warning disappear.

kduprey commented 2 weeks ago

Is there a way to resolve this warning with the latest version of jiti? Or would this be a defect of the t3-env library?