Skip to content

build fails with top level await #13277

Answered by andriygm
TheLudd asked this question in Q&A
Discussion options

You must be logged in to vote

You could target esnext for only the SSR build (client build will still target modern browsers) with something like this in yourvite.config.ts:

export default defineConfig(({ isSsrBuild }) => ({
  plugins: [reactRouter(), tsconfigPaths()],
  build: {
    target: isSsrBuild ? "esnext" : undefined,
  },
}));

Theoretically, transpiling to different targets between the server and client should still produce the same DOM output, so the risk of hydration mismatch is probably little to none, but it's probably still safer to maintain the same build target between client and server:

export default defineConfig({
  plugins: [reactRouter(), tsconfigPaths()],
  build: {
    target: "esnext",
  },
});

B…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by TheLudd
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants