Closed Volna13 closed 1 year ago
Try ts-jest-resolver
.
Try
ts-jest-resolver
.
It still not work for me(ts-jest-resolver Didn't change behavior at all). I have changed jest.config.js and now i have another errors
jest.config.js
import preset from 'ts-jest/presets/index.js';
/** @type {import('ts-jest').JestConfigWithTsJest} */
export default {
...preset.defaultsESM,
resolver: 'ts-jest-resolver',
setupFilesAfterEnv: ['./src/tests/jest.setup.ts'],
transform: {
'^.+\\.tsx?$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
useESM: true,
},
],
},
};
Error
The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.
8 const __dirname = dirname(fileURLToPath(import.meta.url));
Looks like transformation issue. You are trying to use ts-jest
, but it is not part of Jest. It is maintain in a separate repo. You should file the issues there.
I would suggest creating a minimal reproduction repo. That would help you to understand the problem better. Also I would be easier for others to a quick look.
Ran into this today. Fixed with this Jest config property: extensionsToTreatAsEsm
Add to your jest.config.js
:
extensionsToTreatAsEsm:['.ts']
Thanks. Hope that helps. If not, please open new issue with minimal reproduction repo. I will close this issue, because the "Cannot find module" error (which was the initial problem) also seems to be gone.
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.
I am switching from cjs to esm. I've fixed all the issues except jest running issues. He just refuses to work.
Here is datails.
/jest.config.js
/src/tests/jest.setup.ts
/package.json
tsconfig.json
Error after run npm run test