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

feat(config): show warning message for nodejs ts target version mismatch #1678

Merged
merged 1 commit into from
May 25, 2020
Merged

feat(config): show warning message for nodejs ts target version mismatch #1678

merged 1 commit into from
May 25, 2020

Conversation

ahnpnl
Copy link
Collaborator

@ahnpnl ahnpnl commented May 25, 2020

Summary

Often I see ts-jest users run into the problem and turned out that ones set the target version in their tsconfig to be incompatible with their NodeJs version. This can result in some features of TypeScript when transpiling to commonjs aren't supported by a specific NodeJs version.

This PR is to add a warning message for NodeJs 10/12 users that they should use recommended target by TypeScript team at https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping

Test plan

Added unit test and e2e test. Green CI

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

@ahnpnl ahnpnl requested a review from kulshekhar as a code owner May 25, 2020 08:18
@ahnpnl ahnpnl changed the title feat(config): add warning message for nodejs ts target version mismatch feat(config): show warning message for nodejs ts target version mismatch May 25, 2020
@coveralls
Copy link

coveralls commented May 25, 2020

Pull Request Test Coverage Report for Build 4927

  • 6 of 6 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.008%) to 92.818%

Totals Coverage Status
Change from base Build 4925: -0.008%
Covered Lines: 1066
Relevant Lines: 1101

💛 - Coveralls

@ahnpnl ahnpnl merged commit 085bdf5 into kulshekhar:master May 25, 2020
@ahnpnl ahnpnl deleted the feat-target-warning branch May 25, 2020 11:41
@eric-burel
Copy link

eric-burel commented Jun 5, 2020

I gety

ts-jest[config] (WARN) There is a mismatch between your NodeJs version v10.16.0 and your TypeScript target undefined.

While my config is:

  "compilerOptions": {
    "allowJs": true,
    "alwaysStrict": true,
    "baseUrl": "./",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "lib": ["dom", "es2017"],
    "module": "esnext",
    "moduleResolution": "node",
    "noEmit": true,
    "noFallthroughCasesInSwitch": true,
    "noUnusedLocals": false, // won't fail on unused variables
    "noUnusedParameters": false,
    "paths": {
      "@vulcan/*": ["packages/@vulcan/*", "node_modules/@vulcan/*"],
      "~/*": ["src/*"]
    },
    "resolveJsonModule": true,
    "skipLibCheck": true,
    "strict": false,
    "sourceMap": true,
    "target": "esnext"
  },

Any idea how I could get past this? Is the use of "esnext" problematic?

Edit: note that this is my main tsconfig.json. I pass a tsconfig.jest.json to ts-jest which extends this one, which could explain the undefined?

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jun 5, 2020

you can get pass the warning message by using the correct target as recommended from TypeScript team. That is to prevent ts-jest users run into unsupported features because of nodejs doesn't always support everything which is compiled with a specific target.

If you cannot change your tsconfig, you can create a new tsconfig for testing only, which will extend the base tsconfig. In that testing only tsconfig, you can set the target as recommended.

@merlinnot
Copy link

I can confirm that this doesn't work with extends. I have a correct target specified in a base config.

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jun 5, 2020

did you try clear cache ? Do you specify your extend tsconfig to ts-jest tsConfig option ?

@eric-burel
Copy link

Ok, it seems that it works when extending the base config, at lest I can't repro @merlinnot issue (having the right target but only in the base config, not the extended test config).

So my initial issue seemed to happen when using "esnext". It won't tell that "esnext" is wrong, but only "undefined". I guess the warning message could be improved to tell whether no target is found, or the wrong target is found.

Note that it indeed make sense to have a specific target for the test config, since Jest is a runtime environment on its own.

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jun 5, 2020

PR to improve it is welcome :), the message is specified here. The code to use the message here

The most common case I can see is with optional chaining. Some users come to ask the question why optional chaining doesn't work and turned out that they set the wrong target for tsconfig and their NodeJs version couldn't read the compiled output of optional chaining.

@eric-burel
Copy link

Yeah weird, it shouldn't display "undefined" in this scenario according to your code. Anyway that's a edge case, thanks for the very quick answers!

@hbroer
Copy link

hbroer commented Jun 10, 2020

is it possible to turn of this warning? We have no problem with transpile to esnext on any project with ts-jest. Maybe because we use babel to do that job.

module.exports = {
    globals: {
        'ts-jest': {
            babelConfig: ".babelrc",
        }
    },
};

@ahnpnl
Copy link
Collaborator Author

ahnpnl commented Jun 10, 2020

Hi, I think it is a bug. It should only consider the case when users don’t use Babel.

PR is welcome :)

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

Successfully merging this pull request may close these issues.

6 participants