I'm having these error messages when running a command with ts-node:
metaplex/js/packages/cli/src/candy-machine-v2-cli.ts:499:16 - error TS2569: Type 'Uint8Array' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
499 ...thisSlice.slice(4, 36).filter(n => n !== 0),
metaplex/js/packages/cli/src/candy-machine-v2-cli.ts:502:16 - error TS2569: Type 'Uint8Array' is not an array type or a string type. Use compiler option '--downlevelIteration' to allow iterating of iterators.
502 ...thisSlice.slice(40, 240).filter(n => n !== 0),```
I've already tried updating tsconfig.json target to es5 and es2015 and also adding the downlevelIteration: true line, but the error keep the same.
What should I do?
Because you haven't provided a minimal, reproducible example, I'll show you a self-contained example to demonstrate a working ESM project configuration using
ts-node
and the current LTS release of Node.js (v16.14.0
at the time I post this answer).I'll show the contents of each file and detail the important configuration options in comments and/or after the contents:
./package.json
:devDependencies
:@types/node
: needed for Node.js APIsts-node
: part of your questiontypescript
: part of your questiontype
should be"module"
for ESMscripts.dev
: I added this npm script to make running the project easier to type on the command line. Thets-node
docs section about ES modules explains the requirements for enabling ESM support and shows using a CLI argument to run code in ESM mode:ts-node --esm src/main.ts
.Now, to run your program with
ts-node
, you don't need to remember this syntax: you just need to use the commandnpm run dev
../tsconfig.json
:See comments above.
"compilerOptions"
are the ones in the first section under "Node 16 ESM options"../src
directory of your project../src/main.ts
:There's the example code, which uses the same spread syntax on a
Uint8Array
, just like in your question.Now, let's install everything and run it:
Success: The output is as expected with no problems.