Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

vite build fail,when use vite-plugin-top-level-await #214

Closed
menghany opened this issue Dec 6, 2024 · 5 comments · Fixed by #222
Closed

vite build fail,when use vite-plugin-top-level-await #214

menghany opened this issue Dec 6, 2024 · 5 comments · Fixed by #222

Comments

@menghany
Copy link

menghany commented Dec 6, 2024

When building my project, I want to ensure compatibility with older browsers, so I modified the build configuration in the demo. However, after completing the build, it fails to run.
image
my build command success
cd /examples/vite-vite/vite-remote
pnpm run build
When i run
pnpm run preview
is error
image
image

@gioboa
Copy link
Collaborator

gioboa commented Dec 6, 2024

Hi @menghany,
I reproduced the problem and hacked the compiled like this

from

i()

to

setTimeout(() => i(), 0);

and now it's working. So I'm woundering if it's a specific problem of vite-plugin-top-level-await 🤔

@deizianens
Copy link

deizianens commented Dec 6, 2024

I have the exact same error on my app, also using vite-plugin-top-level-await and running vite preview command.
i is not a function on hostInit
Did you find any solution to this?

I fixed that by not using this plugin at all.

@gioboa
Copy link
Collaborator

gioboa commented Dec 6, 2024

You can use the build -> target Vite config.
Which browser do you need to support?

@deizianens
Copy link

@gioboa The most used browsers: chrome, safari, edge...
Think I can use build target: esnext, right?

@gioboa
Copy link
Collaborator

gioboa commented Dec 6, 2024

Yep, even if it's called chrome89 it works with other browsers too.
Here is the official docs

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants