Warning message running `npm test`
Using this template unmodified, I get this message running npm test:
ts-jest[config] (WARN) message TS151001: If you have issues related to imports, you should consider setting `esModuleInterop` to `true` in your TypeScript configuration file (usually `tsconfig.json`). See https://blogs.msdn.microsoft.com/typescript/2018/01/31/announcing-typescript-2-7/#easier-ecmascript-module-interoperability for more information.
With this dummy test file:
import * as path from 'path'
test("dummy test", () => {
expect(path.join("xyz", "pdq")).toEqual("xyz/pdq")
})
The message remains no matter in which tsconfig.json I put the following lines:
"allowSyntheticDefaultImports": true,
"esModuleInterop": true,
I have not written any tests with this setup and I do not have a lot of time but I will accept a PR if you write one.
Cheers.
In my case setting "esModuleInterop": true fixed the problem. Remember this esModuleInterop will also set allowSyntheticDefaultImports to true. So no need to set this one to true explicitly. Details below ⬇️
https://www.typescriptlang.org/tsconfig#esModuleInterop
Having the same issue
In my case, setting "esModuleInterop": true did in fact suppress these warnings (ts-jest 29.1.2, jest 29.7.0) so I can't reproduce this exact bug as described.
But I don't want esModuleInterop true (which always emits extra bulky shim code), searched for how to disable these pesky warnings, and found this page. If anybody else is in a similar situation, you can suppress the warnings explicitly by adjusting your jest.config from this style of ts-jest invocation:
module.exports = {
transform: {
"^.+\\.(t|j)s$": "ts-jest"
}
}
to this:
module.exports = {
transform: {
"^.+\\.(t|j)s$": ['ts-jest', { diagnostics: { ignoreCodes: ['TS151001'] } }],
}
}