Reputation: 15877
I get a strange compiler error. It states: RangeError: Value undefined out of range for undefined options property undefined
.
My feeling so far is, that the compiler runs internally into a loop and fills up a Map
until it is full. My best guess is, that this is connected to some faulty type declaration in our own code base.
My problem is, that the compiler is not telling which part of my code base is the issue for this problem and happened after a package update. So I don't see any hint which specific part of our code base is the root cause for this. How can I convince TypeScript to tell me this?
The whole stack trace looks like this:
$ yarn tsc
yarn run v1.22.4
$ /myProject/app/node_modules/.bin/tsc
/myProject/app/node_modules/typescript/lib/tsc.js:90679
throw e;
^RangeError: Value undefined out of range for undefined options property undefined
at Map.set (<anonymous>)
at recursiveTypeRelatedTo (/myProject/app/node_modules/typescript/lib/tsc.js:50962:30)
at isRelatedTo (/myProject/app/node_modules/typescript/lib/tsc.js:50543:34)
at checkTypeRelatedTo (/myProject/app/node_modules/typescript/lib/tsc.js:50229:26)
at isTypeRelatedTo (/myProject/app/node_modules/typescript/lib/tsc.js:50192:24)
at isTypeSubtypeOf (/myProject/app/node_modules/typescript/lib/tsc.js:49480:20)
at /myProject/app/node_modules/typescript/lib/tsc.js:47289:90
at Object.some (/myProject/app/node_modules/typescript/lib/tsc.js:658:25)
at _loop_14 (/myProject/app/node_modules/typescript/lib/tsc.js:47289:45)
at removeStringLiteralsMatchedByTemplateLiterals (/myProject/app/node_modules/typescript/lib/tsc.js:47294:21)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Background
This happened after I upgraded react-hook-form from version 6 to 7, with no other changes to the code base.
I tried already the following (all with the same outcome):
tsc -b --verbose
Side notes
Upvotes: 2
Views: 982
Reputation: 11
I also had the exact same error on running tsc
(both on snowpack and stand-alone).
In my case, it was caused by "Circular Dependency" issue.
I used the indexed access type in a specific part of the newly added code, and the file in which the object type is defined and the file in which the property type is defined are separated and referenced.
So, I changed the code that used the indexed access type to the actual property type.
So the error no longer occurs.
Upvotes: 1
Reputation: 5863
Error is pretty desriptive (or it isn't)? It Looks like you have (or library that you are using) some kind of infinite loop somewhere.
Map
can store up to 16777216
(2^24
) values, after you store this amount and try to add 1 more, you will get this weird RangeError
.
Here is example how you can re-create this error (wait around 10s
):
const testMap = new Map()
Array.from(
{ length: Math.pow(2, 24) },
(_, i) => testMap.set(i, 'x')
)
console.log(testMap.get(16777215)) // last value, no error
testMap.set(Math.pow(2, 24) + 1, 'x') // error will occur
It's hard to say how solve you exact problem without your entire code, but I would do something like this:
Map
declarations and comment them,Map
declarations 1 by 1 and check after which one you will get RangeError
.If error won't disappear after this, it's probably case with 1 of libraries that you recently updated. In this case the only way to solve this, might be revert project to last working version and apply changes step by step meanwhile looking at outcome.
What's even more interesting, if you will treat standard Object
as a "Map" you can store up to 2^32 - 1
values (Array.length).
Here is example how to re-create this error (wait around 10s
, might crash earlier, is up to RAM and Browser):
const testObj = {}
Array.from(
{ length: Math.pow(2, 32) - 1 },
(_, i) => testObj[i] = i
)
console.log(testObj[Math.pow(2, 32) - 1]) // last value, no error
testObj[Math.pow(2, 32)] // RangeError: Invalid array length
Alternative example of above:
Array.from({ length: Math.pow(2, 32) }) // RangeError
Upvotes: 0