oscklm
oscklm5mo ago

Issue with asyncMap in convex-helpers and Next.js 14.2.5

I'm getting this issue when trying to build my next.js app within my monorepo. I'm using the convex-helpers in my backend package. I'm not sure what i can do, my target is set to ESNext for both next.js and my backend package.
yarn run v1.22.19
│ $ next build
│ ▲ Next.js 14.2.5
- Environments: .env.production

│ Creating an optimized production build ...
│ ✓ Compiled successfully
│ Linting and checking validity of types .Failed to compile.

│ ../../node_modules/convex-helpers/index.ts:15:22
│ Type error: Type 'Iterable<FromType>' can only be iterated through when using the '--downlevelIteration' flag
│ or with a '--target' of 'es2015' or higher.

13 | const promises: Promise<ToType>[] = [];
14 | let index = 0;
> 15 | for (const item of await list) {
| ^
16 | promises.push(asyncTransform(item, index));
17 | index += 1;
18 | }
│ error Command failed with exit code 1.
│ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
│ command finished with error: command (/Users/oscklm/Code/work/flimmer-monorepo/apps/dashboard) /var/folders/rn
/rd71yf_115b60w3h6jfv16840000gn/T/yarn--1722335907430-0.34139340179029687/yarn run build exited (1)
└────>
@flimmer/dashboard#build: command (/Users/oscklm/Code/work/flimmer-monorepo/apps/dashboard) /var/folders/rn/rd71yf_115b60w3h6jfv16840000gn/T/yarn--1722335907430-0.34139340179029687/yarn run build exited (1)
yarn run v1.22.19
│ $ next build
│ ▲ Next.js 14.2.5
- Environments: .env.production

│ Creating an optimized production build ...
│ ✓ Compiled successfully
│ Linting and checking validity of types .Failed to compile.

│ ../../node_modules/convex-helpers/index.ts:15:22
│ Type error: Type 'Iterable<FromType>' can only be iterated through when using the '--downlevelIteration' flag
│ or with a '--target' of 'es2015' or higher.

13 | const promises: Promise<ToType>[] = [];
14 | let index = 0;
> 15 | for (const item of await list) {
| ^
16 | promises.push(asyncTransform(item, index));
17 | index += 1;
18 | }
│ error Command failed with exit code 1.
│ info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
│ command finished with error: command (/Users/oscklm/Code/work/flimmer-monorepo/apps/dashboard) /var/folders/rn
/rd71yf_115b60w3h6jfv16840000gn/T/yarn--1722335907430-0.34139340179029687/yarn run build exited (1)
└────>
@flimmer/dashboard#build: command (/Users/oscklm/Code/work/flimmer-monorepo/apps/dashboard) /var/folders/rn/rd71yf_115b60w3h6jfv16840000gn/T/yarn--1722335907430-0.34139340179029687/yarn run build exited (1)
10 Replies
Michal Srb
Michal Srb5mo ago
Try adding "target": "es2015" to compilerOptions in your top level tsconfig.json (the one used by Next.js) It sure would be nice for TypeScript to only consider the types from convex and not any runtime behavior, but that requires a more complicated setup. Did you use one of our templates to initiate the project?
oscklm
oscklmOP5mo ago
Yeah it's actually the convex expo monorepo starter. But without any of the apps in the starter though, as we migrated a bunch from our old repo, recently. I tried changing the targets 1 by one, both for the next.js tsconfig and the others present in the repo. I know for a fact we changed the one inside the /convex folder, to have javascript sets, but changing that back to es2015 also doesnt work.
Michal Srb
Michal Srb5mo ago
Higher target should be fine. The error comes from Next.js build, so it must be the tsconfig used by Next.js Can you add skipLibCheck ?
oscklm
oscklmOP5mo ago
Yeah. Hmm, i'll see if i can gather a bit more information to go from Haven't tried that yet, will do! Ohh its already there, so here are our current tsconfigs next js:
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
{
"compilerOptions": {
"lib": ["dom", "dom.iterable", "esnext"],
"allowJs": true,
"skipLibCheck": true,
"strict": true,
"noEmit": true,
"esModuleInterop": true,
"module": "esnext",
"moduleResolution": "bundler",
"resolveJsonModule": true,
"isolatedModules": true,
"jsx": "preserve",
"incremental": true,
"plugins": [
{
"name": "next"
}
],
"paths": {
"@/*": ["./*"]
}
},
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
"exclude": ["node_modules"]
}
packages/backend/convex:
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* These settings are not required by Convex and can be modified. */
"allowJs": true,
"strict": true,
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,

/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ESNext", "dom"],
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*", "auth.ts"],
"exclude": ["./_generated"]
}
{
/* This TypeScript project config describes the environment that
* Convex functions run in and is used to typecheck them.
* You can modify it, but some settings required to use Convex.
*/
"compilerOptions": {
/* These settings are not required by Convex and can be modified. */
"allowJs": true,
"strict": true,
"moduleResolution": "Bundler",
"jsx": "react-jsx",
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,

/* These compiler options are required by Convex */
"target": "ESNext",
"lib": ["ESNext", "dom"],
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"isolatedModules": true,
"noEmit": true
},
"include": ["./**/*", "auth.ts"],
"exclude": ["./_generated"]
}
monorepo root:
{
"compilerOptions": {},
"extends": "expo/tsconfig.base"
}
{
"compilerOptions": {},
"extends": "expo/tsconfig.base"
}
Pretty odd. I also don't even use the asyncMap function, so it's a bit annoying i cant just have next.js ignore that completely. I've tried various tsconfig settings now. Cleaned my cache each type, nothing seems to change it unfortunately. Okay, i got it working now. Unsure if it truly was the issue. But clearing the turbo cache and adding this worked: "downlevelIteration": true,
murad
murad5mo ago
thx pal, had the same issue and "downlevelIteration": true works perfectly
David Alonso
David Alonso4mo ago
hey guys, i have a similar setup and running into the same after upgrading to convex-helpers@0.1.52 Is the conclusion to have the following lines in the nextjs tsconfig.json?
"target": "es2015",
"downlevelIteration": true,
"skipLibCheck": true,
"target": "es2015",
"downlevelIteration": true,
"skipLibCheck": true,
I can't seem to get rid of the error even though the app runs fine and I can do:
turbo clean
turbo build
turbo clean
turbo build
successfully... Any ideas?
ballingt
ballingt4mo ago
You made these changes and you still have a the TypeScript error?
David Alonso
David Alonso4mo ago
Yep
ballingt
ballingt4mo ago
@David Alonso could you share the code, and if you can a repro? You say running into the same, could you show the error just to be sure?
David Alonso
David Alonso4mo ago
Will follow up soon, currently i have a very broken build I'm working on which might hide things

Did you find this page helpful?