Open hooty868 opened 1 month ago
Same issue. Next.js: v14.2.3, @t3-oss/env-nextjs: 0.10.1, jest: 29.7.0, typescript: 5.4.5
My jest.config.js
is pretty default:
const nextJest = require('next/jest');
const createJestConfig = nextJest({
dir: './',
});
const config = {
coverageProvider: 'v8',
testEnvironment: 'jsdom',
};
module.exports = createJestConfig(config);
Here is my current solution.
Add the packages that need to be transpiled in next.config.js:
{
...
transpilePackages: [
...
'@t3-oss/env-nextjs',
'@t3-oss/env-core',
],
}
Due to Jest being unable to parse untranspiled ESM packages, it is necessary to have webpack transpile them first. In Next.js, this can be accomplished by adding transpilePackages to next.config.js
.
backdround
When running individual Jest tests, I encounter an error due to the package not being resolved correctly.
the test will show this error: `
`
});`
Relevant Package Versions:
Project tsconfig settings:
{ "compilerOptions": { "target": "es5", "lib": ["dom", "dom.iterable", "esnext"], "allowJs": true, "skipLibCheck": true, "strict": true, "forceConsistentCasingInFileNames": true, "noEmit": true, "esModuleInterop": true, "module": "esnext", "moduleResolution": "node", "resolveJsonModule": true, "isolatedModules": true, "jsx": "preserve", "incremental": true, "baseUrl": "src", "paths": { "@/*": ["*"] } }, "include": ["next-env.d.ts", "next.config.js", "**/*.ts", "**/*.tsx", "src/env.mjs"], "exclude": ["node_modules"] }