v8-to-istanbul: Cannot read properties of undefined (reading 'endCol')
I am getting Cannot read properties of undefined (reading 'endCol')
when trying to generate coverage after a jest
test run when using @swc/jest
as a transformer.
Error
TypeError: Cannot read properties of undefined (reading 'endCol')
at module.exports.sliceRange (/workspace/node_modules/.pnpm/v8-to-istanbul@9.0.1/node_modules/v8-to-istanbul/lib/range.js:30:54)
at /workspace/node_modules/.pnpm/v8-to-istanbul@9.0.1/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:139:19
at Array.forEach (<anonymous>)
at /workspace/node_modules/.pnpm/v8-to-istanbul@9.0.1/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:125:20
at Array.forEach (<anonymous>)
at V8ToIstanbul.applyCoverage (/workspace/node_modules/.pnpm/v8-to-istanbul@9.0.1/node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:124:12)
Details
During this call: https://github.com/istanbuljs/v8-to-istanbul/blob/b5ecd8242cf64389c9a656d78530bd0428edf195/lib/v8-to-istanbul.js#L205
_maybeRemapStartColEndCol({
count: 0,
startOffset: 340,
endOffset: 348
})
It receives object with all properties null
from originalPositionFor
here: https://github.com/istanbuljs/v8-to-istanbul/blob/b5ecd8242cf64389c9a656d78530bd0428edf195/lib/source.js#L105
Which causes it to fail somewhere down the line.
Source File
export const noop = () => Promise.resolve();
export const noopSync = () => {
/* noop */
};
Transformed File
If I transform it with @swc
with source maps enabled, I get this:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
noop: ()=>noop,
noopSync: ()=>noopSync
});
const noop = ()=>Promise.resolve();
const noopSync = ()=>{
/* noop */ };
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbIi93b3Jrc3BhY2Uvc3JjL3V0aWxzL2Z1bmN0aW9uLnRzIl0sInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCBjb25zdCBub29wID0gKCkgPT4gUHJvbWlzZS5yZXNvbHZlKCk7XG5leHBvcnQgY29uc3Qgbm9vcFN5bmMgPSAoKSA9PiB7XG4gIC8qIG5vb3AgKi9cbn07XG4iXSwibmFtZXMiOlsibm9vcCIsIm5vb3BTeW5jIiwiUHJvbWlzZSIsInJlc29sdmUiXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7Ozs7OztJQUFhQSxJQUFJLE1BQUpBO0lBQ0FDLFFBQVEsTUFBUkE7O0FBRE4sTUFBTUQsT0FBTyxJQUFNRSxRQUFRQyxPQUFPO0FBQ2xDLE1BQU1GLFdBQVcsSUFBTTtBQUM1QixRQUFRLEdBQ1YifQ==
Source map
{
"version": 3,
"sources": [
"/workspace/src/utils/function.ts"
],
"sourcesContent": [
"export const noop = () => Promise.resolve();\nexport const noopSync = () => {\n /* noop */\n};\n"
],
"names": [
"noop",
"noopSync",
"Promise",
"resolve"
],
"mappings": "AAAA;;;;;;;;;;;IAAaA,IAAI,MAAJA;IACAC,QAAQ,MAARA;;AADN,MAAMD,OAAO,IAAME,QAAQC,OAAO;AAClC,MAAMF,WAAW,IAAM;AAC5B,QAAQ,GACV"
}
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 17
- Comments: 24 (5 by maintainers)
Commits related to this issue
- Fix issue with end out of range error https://github.com/istanbuljs/v8-to-istanbul/issues/198#issuecomment-1310007608 — committed to hurstindustries/v8-to-istanbul by hurstindustries 2 years ago
- Fix issue with end out of range error https://github.com/istanbuljs/v8-to-istanbul/issues/198#issuecomment-1310007608 — committed to hurstindustries/v8-to-istanbul by hurstindustries 2 years ago
- Workaround for https://github.com/istanbuljs/v8-to-istanbul/issues/198 — committed to winglang/wing by skorfmann 10 months ago
Not sure if this will help anyone, but I encountered the same issue, the file was exporting constants only:
After tracking down the issue, I figured out the solution, I just added one space above the very first
export
, so my file became:I guessed it because in the file
range.js
, I found that theend
variable was-1
, so by adding that comment line on top of the file, the issue went away.Having an
export const
in the first line of the file was the problem for me. Adding a comment in line 1 and a return in line 2 as @aladinflux did worked for me.🤷♂️
i’ve run into this too, i’ve pinned
@swc/core
at1.3.3
, every patch release after that seems to cause this errortoday’s latest, doesn’t work.
I ran into this today as well and really appreciate all the suggestions here but have to many tests to go one by one. In order to find the file that had
export const
at the top I modified./node_modules/v8-to-istanbul/lib/v8-to-istanbul.js:146
. Wrapping the call site in a try/catch and logging the path shows you which file is the issue. Hope it helps until a fix can be merged 👍Ran into this same issue, and pinning the
@swc/jest
version didn’t work. @aladinflux, thank you for the idea to check for top-line exports; that ended up being the problem.For other folks’ reference, I had to:
As @aladinflux and @mitestainer, adding a comment in line 1 of a file that was only exporting constants solved the issue (which was previously encountered in another project, and back then strangely resolved by lowering axios from 1.2.3 to 1.1.3). Quite curious as to why it happens.
I lowered @swc/jest to version 2.20 and it worked!
Hi, same issue experienced here. Independently to a proper and source based fix we have an easy patch applied at @jest/reporters/v8-to-istanbul@^9.0.1
That makes end not go beneath start position. I would suggest to add that to a PR but knowing that is not a fix of the problem creator but a problem stopper.