`env.mjs` as opposed to `env.cjs` or `env.js`

Heya, is there a reason why the env definition is in an mjs file as opposed to cjs or simply js? Reason I'm asking is because I'm trying to setup websockets and mjs won't work as we're compiling with commonjs.
6 Replies
Sybatron
Sybatron2y ago
you should be able able to put them in .ts too
MrLowLevel
MrLowLevelOP2y ago
I think the reason ts doesn't work is because of this line in next.config.mjs
!process.env.SKIP_ENV_VALIDATION && (await import('./src/env.mjs'))
!process.env.SKIP_ENV_VALIDATION && (await import('./src/env.mjs'))
dan
dan2y ago
I'm assuming this is the old env setup. But iirc the env is imported in the next.config.mjs and you cant import ts into that (or commonjs iirc) Either that or mjs is used because modules are just better :3
MrLowLevel
MrLowLevelOP2y ago
yeah our t3 init version is 7.5.1 let me see if anything breaks if I just convert env.mjs to env.js in all the places ok yeah then next gets mad
import { z } from 'zod'
^^^^^^

SyntaxError: Cannot use import statement outside a module
import { z } from 'zod'
^^^^^^

SyntaxError: Cannot use import statement outside a module
Sybatron
Sybatron2y ago
you have to change the imports to require if you do commonjs import is only for modules
MrLowLevel
MrLowLevelOP2y ago
yah indeed testing that now
Want results from more Discord servers?
Add your server