vechain-sdk-js
vechain-sdk-js copied to clipboard
Bug :: SDK core import with NextJS
When importing the SDK Core in a NextJs project 14.1.1, when trying to build, I get the following error:
Type error: Type 'IterableIterator
' can only be iterated through when using the '--downlevelIteration' flag or with a '--target' of 'es2015' or higher. 150 | const nBits = nBytes * 8; 151 |
152 | for (const hash of this.hashes.keys()) { | ^ 153 | distribute(hash, k, nBits, (index, bit) => { 154 | bits[index] |= bit; 155 | return true; error Command failed with exit code 1.
Diagnosis
The origin of the problem is Map
type exposes keys
through the type IterableIterator<number>
, introduced with ES2015 or higher.
The error message"Type error: Type 'IterableIterator
Therapy
The tsconfig.json
file of the NextJS module must includes in the "compilerOptions"
both
-
"target": "es2020"
-
"types": ["@testing-library/jest-dom"]
The "target": "es2020"
is required because the SDK uses BigInt
type not available before.
Omitting "types": ["@testing-library/jest-dom"]
prevents "target": "es2020"
to be evaluated.
Once yarn install
and yarn build
succeed, the types are cached in
- apps/sdk-nextjs-integration/.next
- apps/sdk-nextjs-integration/node_modules
- apps/sdk-nextjs-integration/next-env.d.ts
those directories and files must be deleted before new
compilerOptions
are effective.