solid-start: [Bug]: top-level `await` does not work with libraries when enabled (and is not supported out of the box)
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior π―
Use npm create solid to make a basic app, then put a top-level await something in a module, and youβll get an error during npm run build like so:
ERROR Transform failed with 1 error: 10:24:53 AM
/Users/trusktr/src/showcase/.vinxi/build/ssr/ssr.js:1:17460: ERROR: Top-level await is not available in the configured target environment ("es2019")
Expected behavior π€
It should just work out of the box. It works in all JS runtimes and browsers out of the box.
Steps to reproduce πΉ
Problem 1:
Steps:
npm create solid- put an
await something()at the top level of a module - run
npm run build - see error in terminal after loading the app in browser
The error will look something like this:
ERROR Transform failed with 1 error: 10:24:53 AM
/Users/trusktr/src/showcase/.vinxi/build/ssr/ssr.js:1:17460: ERROR: Top-level await is not available in the configured target environment ("es2019")
To fix the problem, the following will not work:
export default defineConfig({
vite: {
build: { target: 'esnext' },
},
})
but one would think that it would, because this is what we see when we look at intellisense:
In the screenshot we can see that the auto-completion in VS Code will give us a strong hint that setting this option will work. But thatβs not the case (when it comes to application code).
Instead, we must set a different option of the same name at another location, which is not so obvious considering that Vite uses esbuild and one may very well assume the vite esbuild config will do the trick:
export default defineConfig({
server: {
esbuild: { options: { target: 'esnext' } },
},
})
Problem 2:
If you import a library from npm that has top-level await, thereβs no way to make it work. Setting either of the two options above will not work!
Steps:
npm create solidnpm install yoga-layoutnpm run dev- see error in terminal after loading the app in browser
The error will look something like this,
β [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
node_modules/yoga-layout/dist/src/index.js:13:26:
13 β const Yoga = wrapAssembly(await loadYoga());
β΅ ~~~~~
8:19:44 PM [vite] error while updating dependencies:
Error: Build failed with 1 error:
node_modules/yoga-layout/dist/src/index.js:13:26: ERROR: Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)
at failureErrorWithLog (/Users/trusktr/src/showcase/node_modules/vite/node_modules/esbuild/lib/main.js:1472:15)
at /Users/trusktr/src/showcase/node_modules/vite/node_modules/esbuild/lib/main.js:945:25
at /Users/trusktr/src/showcase/node_modules/vite/node_modules/esbuild/lib/main.js:1353:9
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
which as you can imagine is frustrating because yoga-layout is a 3rd-party library, and the neither of the two target configs is helping.
The error says my target environment is chrome87. Why is that, if Iβve specified esnext, when is comes to the node_modules dependency?
Context π¦
All JS runtimes support top-level await natively for a long time now. Solid Start should too!
Your environment π
npmPackages:
β― npm ls
showcase@ /Users/trusktr/src/showcase
βββ @babel/plugin-proposal-decorators@7.24.7
βββ @solidjs/router@0.14.3
βββ @solidjs/start@1.0.6
βββ @types/three@0.167.2
βββ lume@0.3.0-alpha.43
βββ prettier@3.3.3
βββ solid-js@1.8.21
βββ vinxi@0.4.1
βββ yoga-layout@3.1.0
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 4
- Comments: 16 (2 by maintainers)
To those who run into this issue; As the author said in the first comment, the following workaround works:
Also, the following works too (which seems to be preferred):
why is this issue still open then?
It now is 2025, and Iβm running into this issue in trying to deploy my first Solid Start site. It appears that weβre using 2.10.4 of nitro as of the time of this writing, but we get the same error: Top-level await is not available in the configured target environment (βes2019β).
Do we have any updates on the path forward for this?