Skip to content
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

Remix Vite Top-level await is not available in the configured target environment #3646

Closed
SpencerDuball opened this issue Jan 30, 2024 · 4 comments

Comments

@SpencerDuball
Copy link
Contributor

After upgrading to Remix with Vite I was getting this error:

✘ [ERROR] Top-level await is not available in the configured target environment ("chrome87", "edge88", "es2020", "firefox78", "safari14" + 2 overrides)

    ../../node_modules/.pnpm/sst@2.38.7/node_modules/sst/node/util/index.js:15:21:
      15 │ const _placeholder = await parseEnvironment();

There are a few answers out there that suggest updating the TSConfig target to "ESNext" but this probably will affect the output client bundle and cause issues for people with older browsers. Instead I found this solution:

export default defineConfig({
  server: { port: 3000 },
  plugins: [remix(), tsconfigPaths()],
  optimizeDeps: { esbuildOptions: { target: "esnext" } }, // <-- Set this to resolve issue.
});

Got this solution from: mozilla/pdf.js#17245

@SpencerDuball
Copy link
Contributor Author

Added for documentation purposes only, not an active issue.

@castarco
Copy link

castarco commented Feb 1, 2024

What would be the solution for the case of Astro? (as opposed to NextJS)

@SpencerDuball
Copy link
Contributor Author

I actually have not used Astro so I am not familiar, also this fix was for Remix (not NextJS) so I am not familiar with that framework either. But the general concept is that you should set the server bundle to ESNext. If you set the browser bundle, you may limit the site to be compatible to folks with only the latest browsers. Since you control the server however, you may support the latest standard.

@castarco
Copy link

castarco commented Feb 2, 2024

Thank you @SpencerDuball , I still didn't manage to do that, but it's a good point. Knowing that there must be some way to configure the server bundling on its own is a helpful indication.

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

No branches or pull requests

2 participants