Resolving “Invalid file coverage object, missing keys, found:data” for NYC

Charles Stover
2 min readDec 29, 2021

If you are merging two NYC coverage reports, for example your Cypress and your Jest coverage reports, you may encounter the cryptic error message: Invalid file coverage object, missing keys, found:data.

There are a lot of moving parts to a coverage report: Babel, Istanbul, Cypress, Jest, NYC, Webpack, and the various modules that intertwine them. Which dependency needs adjustment?

This error is a result of babel-plugin-istanbul and/or istanbul-lib-coverage being different versions for two of your test runners. For example, Jest may be using babel-plugin-istanbul at version 6.0, while Cypress may be using babel-plugin-istanbul at version 6.1. This is an easy error to fall into, through no fault of your own, because each dependency may request “the latest 6.x release of babel-plugin-istanbul” during its first install. If you installed Jest first, when the plugin’s latest version was 6.0, then you installed Cypress later, when the plugin had a 6.1 release, each dependency will use a different version of the plugin, and your lock file will prevent them from aligning.

The problem here is not your configuration — it’s your lock file. To update your lock file to get all sub-dependencies aligned, use the command yarn up -R babel-plugin-istanbul istanbul-lib-coverage. This tells Yarn to recursively check all dependencies for babel-plugin-istanbul and istanbul-lib-coverage, then upgrade them, aligning all test runners to the same version.

For more information, or to discuss this issue with its owners and maintainers, you can check the GitHub issue on the NYC repository.

--

--