0

Even though my tsconfig.json is inline with this answer.

I still get this error:

Top-level 'await' expressions are only allowed when the 'module' option is set to 'es2022', 'esnext', 'system', 'node16', or 'nodenext', and the 'target' option is set to 'es2017' or higher.

tsconfig.json:

{
  "compilerOptions": {
    "target": "es2017",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "downlevelIteration": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "incremental": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve"
  },
  "include": [
    "next-env.d.ts",
    "**/*.ts",
    "**/*.tsx"
  ],
  "exclude": [
    "node_modules"
  ]
}

As you can see the target is set to es2017, module is set to esnext.

Here is the where the error is occuring:

await Promise.all(new Array(10).fill(1).map((_,i) => {
    return prisma.playlist.create({
        data: {
            name: `Playlist #${i+1}`,
            user: {
                connect: {id: user.id},
            },
            songs: {
                connect: songs.map((song) => ({
                    id: song.id,

                }))
            }
        },
    })})
)

At the await statement. I restarted my IDE and tried using es2022 and es5 as targets, but no success.

Ken Adams
  • 83
  • 2
  • 9
  • 1
    `top-level` await only works in ecmascript modules. Make sure yours is one. See this [link](https://v8.dev/features/top-level-await) – smac89 Sep 20 '22 at 18:51

0 Answers0