-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: top-level await
does not work with libraries when enabled (and is not supported out of the box)
#1614
Comments
await
support is not supported out of the box, does not work with librariesawait
is not supported out of the box, does not work with libraries
await
is not supported out of the box, does not work with librariesawait
is not supported out of the box, and does not work with libraries when enabled
await
is not supported out of the box, and does not work with libraries when enabledawait
is not supported out of the box, and does not work with libraries when enabled
Reproduction: https://github.com/lume/showcase/tree/solid-start-issue-1614 git clone [email protected]:lume/showcase.git
cd showcase
git checkout solid-start-issue-1614
npm ci
npm run dev # see error in terminal after loading the app in browser |
await
is not supported out of the box, and does not work with libraries when enabledawait
does not work with libraries when enabled (and is not supported out of the box)
Workaround:A workaround is to do a native // If using typescript, type-only `import` will be fine
import type {Node} from 'yoga-layout'
function getYoga() {
const [yoga, setYoga] = createSignal<typeof import('yoga-layout')>()
const promise = eval("import('https://unpkg.com/[email protected]/dist/src/index.js')")
promise.then(setYoga)
return yoga
}
// ...
const yoga = getYoga()
createEffect(() => {
const yogaModule = yoga()
if (!yogaModule) return
const {default: Yoga, Direction, FlexDirection, Gutter} = yogaModule
// ... use yoga as before ...
}) |
This seems somehow related to the issue of effects not running. https://discord.com/channels/722131463138705510/1275456175462420614 In the above case, I was able to cause effects not to run due to the presence of |
Looks like |
I took Nitro 2.9.7 for a spin, looks like it supports top-level await out of the box. |
I forced nitropack version 2.9.7 in the Solid Start app, but I still get the same top-level await error for yoga-layout when running |
The fix in got rid of the need to use However the issue of // This is not working yet (https://github.com/solidjs/solid-start/issues/1614), so we import with conditional await import()
// import Yoga, {Direction, FlexDirection, Gutter, Wrap, Edge, Justify, Align} from 'yoga-layout'
let Yoga: typeof import('yoga-layout').default
let Direction: typeof import('yoga-layout').Direction
let FlexDirection: typeof import('yoga-layout').FlexDirection
let Gutter: typeof import('yoga-layout').Gutter
let Wrap: typeof import('yoga-layout').Wrap
let Edge: typeof import('yoga-layout').Edge
let Justify: typeof import('yoga-layout').Justify
let Align: typeof import('yoga-layout').Align
if (globalThis.window?.document) {
;({
default: Yoga,
Direction,
FlexDirection,
Gutter,
Wrap,
Edge,
Justify,
Align,
} = (await import('https://unpkg.com/[email protected]/dist/src/index.js')) as typeof import('yoga-layout'))
}
// ... |
The |
Ultimately this is a Nitro defaults issue. I'm hoping upgrading Nitro to v2 when it comes out will fix this soon. |
Is it confirmed this is fixed in Nitro v2? Or do we need to make an issue? Its almost 2025, hard to believe top-level await is not supported when all JS engines do natively. |
Duplicates
Latest version
Current behavior 😯
Use
npm create solid
to make abasic
app, then put a top-levelawait something
in a module, and you'll get an error duringnpm run build
like so: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
await something()
at the top level of a modulenpm run build
The error will look something like this:
To fix the problem, the following will not work:
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:
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 solid
npm install yoga-layout
npm run dev
The error will look something like this,
which as you can imagine is frustrating because
yoga-layout
is a 3rd-party library, and the neither of the twotarget
configs is helping.The error says my target environment is
chrome87
. Why is that, if I've specifiedesnext
, 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 🌎
The text was updated successfully, but these errors were encountered: