question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TSX file with JSX element can not be instrumented

See original GitHub issue

Link to bug demonstration repository

My personal repo: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/tree/code-coverage-issue

What I have done:

1. Install dependencies of code-coverage for cypress and nyc, I did run below command:

yarn add -D @cypress/code-coverage @istanbuljs/nyc-config-typescript @testing-library/cypress nyc source-map-support ts-node istanbul-lib-coverage

2. Other than that, I made below changes in package.json with configs for nyc:

  "nyc": {
    "extends": "@istanbuljs/nyc-config-typescript",
    "all": true,
    "report-dir": ".cypress-coverage",
    "extension": [
      ".js",
      ".ts",
      ".tsx"
    ],
    "include": [
      "public/**/*.{js,ts,tsx}"
    ],
    "exclude": [
      "**/*.test.{ts,tsx}",
      "**/__mocks__/**",
      "**/__test__/**"
    ],
    "reporter": [
      "json",
      "html"
    ]
  },

package.json: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/package.json

3. I run command:

yarn nyc instrument --compact false public .instrumented

I find all the .ts files are instrumented as expected, while .tsx and .js files are not instrumented at all.

Result .ts file[Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/hooks/useDelayedLoader.ts

Result .tsx file[Not Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/components/ContentPanel/ContentPanel.tsx

Result .js file[Not Instrumented]: https://github.com/yizheliu-amazon/anomaly-detection-kibana-plugin/blob/code-coverage-issue/.instrumented/app.js

Expected Behavior

All the .ts, .tsx, .js should be instrumented

Observed Behavior

None of .tsx and .js file is instrumented, while all the .ts files are instrumented as expected.

Troubleshooting steps

  • still occurring when I put cache: false in my nyc config

Environment Information

➜  anomaly-detection-kibana-plugin git:(code-coverage-issue) ✗ npx envinfo@latest --preset nyc
npx: installed 1 in 2.706s

  System:
    OS: macOS High Sierra 10.13.6
    CPU: (4) x64 Intel(R) Core(TM) i7-5557U CPU @ 3.10GHz
    Memory: 1.37 GB / 16.00 GB
  Binaries:
    Node: 10.21.0 - ~/.nvm/versions/node/v10.21.0/bin/node
    Yarn: 1.22.0 - /usr/local/bin/yarn
    npm: 6.14.4 - ~/.nvm/versions/node/v10.21.0/bin/npm
  npmPackages:
    @babel/plugin-proposal-class-properties: ^7.5.5 => 7.10.1
    @babel/plugin-proposal-object-rest-spread: ^7.5.5 => 7.10.1
    @babel/preset-env: ^7.5.5 => 7.10.2
    @babel/preset-react: ^7.0.0 => 7.10.1
    @babel/preset-typescript: ^7.3.3 => 7.10.1
    babel-eslint: ^9.0.0 => 9.0.0
    babel-jest: ^24.8.0 => 24.9.0
    babel-polyfill: ^6.26.0 => 6.26.0
    eslint-plugin-babel: ^5.2.0 => 5.3.0
    istanbul-lib-coverage: ^3.0.0 => 3.0.0
    nyc: ^15.1.0 => 15.1.0
    source-map-support: ^0.5.19 => 0.5.19
    ts-node: ^8.10.2 => 8.10.2
    typescript: 3.0.3 => 3.0.3

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:17

github_iconTop GitHub Comments

11reactions
ilovepumpkincommented, Feb 4, 2021

@SimonDanisch I think one way you can do before this issue gets a TRUE fix is to create a new file (e.g. nyc-config.js) which has same code as the updated @istanbuljs/nyc-config-typescript/index.js. Then define your nyc configuration as below. By this way, you can manage the fix in your git repo, 😃.

{
  "extends": "./nyc-config.js"
}

nyc-config.js

'use strict';
const { parserPlugins } = require('@istanbuljs/schema').defaults.nyc;
module.exports = {
  cache: false,
  parserPlugins: parserPlugins.concat('typescript', 'jsx'),
};

7reactions
loreanvictorcommented, Nov 11, 2020

I am having the same issue and this did not resolve it for me either. After some investigation, it seems to me that parser-plugins option in package.json is somehow ignored, as modifying the content of node_modules/@istanbuljs/nyc-config-typescript/index.js to:

'use strict';

const { parserPlugins } = require('@istanbuljs/schema').defaults.nyc;

module.exports = {
    cache: false,
    parserPlugins: parserPlugins.concat('typescript', 'jsx')
};

works.

Anyways, for now I created a small package nyc-config-tsx which is basically that. With that package installed, extending nyc-config-tsx instead of @istanbuljs/nyc-config-typescript resolved the issue for me, so perhaps it helps resolve your issue as well @yizheliu-amazon, though it would be nice if this was added directly to the official @istanbuljs/nyc-config-typescript or there was an official config like @istanbuljs/nyc-config-tsx.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation - JSX - TypeScript
JSX is an embeddable XML-like syntax. It is meant to be transformed into valid JavaScript, though the semantics of that transformation are ...
Read more >
NPM package cannot be used as a JSX Component
I'm getting similar "TS2786: 'NumberFormat' cannot be used as a JSX component. Its instance type 'NumberFormat<unknown>' is not a valid JSX ...
Read more >
Component cannot be used as a JSX component in React
The error Component cannot be used as a JSX component occurs for multiple reasons, returning an array of JSX elements instead of a...
Read more >
tsx h
Create a TSX file from WAV tape. TSX is disabled in BIOS/microcode/Windows (very possible due to TSX exploits from 2016) you don't really...
Read more >
React plug-in for Application Insights JavaScript SDK
On March 31, 2025, support for instrumentation key ingestion will end. Instrumentation key ingestion will continue to work, but we'll no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found