Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning message running npm test #9

Open
jtlapp opened this issue Oct 13, 2021 · 4 comments
Open

Warning message running npm test #9

jtlapp opened this issue Oct 13, 2021 · 4 comments

Comments

@jtlapp
Copy link

jtlapp commented Oct 13, 2021

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,
@fuzzc0re
Copy link
Owner

fuzzc0re commented Jan 7, 2022

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.

@chety
Copy link

chety commented Mar 14, 2023

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

@Exy63
Copy link

Exy63 commented Apr 20, 2023

Having the same issue

@tmdkamins
Copy link

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'] } }],
  }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants