-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
vite build
error -- Transform failed with 3 errors - Top-level await is not available in the configured target environment
#7969
Comments
I was able to solve this by adding this to my vite.config.ts file: export default defineConfig({
plugins: [
remix({
// appDirectory: "app",
// assetsBuildDirectory: "public/build",
// serverBuildPath: "build/index.js",
// publicPath: "/build/",
serverModuleFormat: "esm",
ignoredRouteFiles: ["**/.*"],
routes(defineRoutes) {
return Promise.resolve(createRoutesFromFolders(defineRoutes));
},
}),
tsconfigPaths(),
],
build: {
target: "ES2022" // <--------- ✅✅✅✅✅✅
},
}); I used the ES2022 {
"include": ["env.d.ts", "**/*.ts", "**/*.tsx"],
"compilerOptions": {
"lib": ["DOM", "DOM.Iterable", "ES2022"],
"isolatedModules": true,
"esModuleInterop": true,
"jsx": "react-jsx",
"moduleResolution": "Bundler",
"resolveJsonModule": true,
"target": "ES2022", // <--------- ✅✅✅✅✅✅
"module": "ES2022",
"strict": true,
"allowJs": true,
"forceConsistentCasingInFileNames": true,
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"~/*": ["./app/*"]
},
// Remix takes care of building everything in `remix build`.
"noEmit": true
}
} References
@pcattori @markdalgleish - maybe the remix vite plugin should use tsconfig settings a user has? |
vite build
error -- Transform failed with 3 errors - Top-level await is not available in the configured target environment
The error message referenced cd node_modules
grep -r "firefox78"
./vite/dist/node/constants.js: 'firefox78', then that gave me an indication it was coming from vite. But I should have probably known that since this error happens when calling package.json
Then I did a google search for the error: |
Thanks for raising this. This is strictly a Vite concern. We're wanting to keep Remix decoupled from your Vite config as much as possible, and this is a good example of something that you're free to configure yourself. If you want your Vite config to automatically sync with your tsconfig, this could be implemented as its own Vite plugin outside of Remix. |
Just ran into this error with remix@2.5.1 while deploying with SST. The fix that worked for me was to set: 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 |
Hi. Can we have a build target for the server bundle and another one for the client bundle? Thx! |
@vmaubert - you can try using the following fields to play around with the In export default defineConfig({
plugins: [
remix({
// ⬇️ The output format of the server build. Defaults to "esm".
serverModuleFormat: "esm",
ignoredRouteFiles: ["**/.*"],
}),
tsconfigPaths(),
],
build: {
target: "ES2022",
},
}); For anyone reading this using esbuild & not vite with remix, my recommendations:
Testing settingsIf you want to play around with the settings, probably best to spin up a quick remix project using the CLI to test the settings # create fresh remix app
npx create-remix --template remix-run/remix/templates/vite-express
# build the app
npm run build
ls build
client server With vite, whats nice is the the client & server build are clearly separated once you build the app: |
@vmaubert Selecting a different build target the server build (SSR) seems to work like that:
This allows me to use top-level await in server code while not messing with browser code. |
Top-level await is not available in the configured target environment remix-run/remix#7969
What version of Remix are you using?
2.2.0
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
app-config.ts
server.ts
Then run
npm run build
Expected Behavior
remix's vite plugin should detect the
tsconfig.json
settings that a user has in their remix project.I have
"target": "ES2022",
in mytsconfig.json
but its not being used for the build step 🤔The text was updated successfully, but these errors were encountered: