You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If your production and development share the same server entry file, then you need to conditionally import dist/server/entry.js.
There are multiple approaches.
1. Top-level await.
// server.jsif(process.env.NODE_ENV==='production'){awaitimport('./path/to/dist/server/entry.js')}// ... server code ...
For environments that don't support top-level await, see alternatives below.
2. Wrap entry code in async function.
// server.jsmain()// We wrap the entire code of server.js in an async function main()asyncfunctionmain(){if(process.env.NODE_ENV==='production'){awaitimport('./path/to/dist/server/entry.js')}// ... server code ...}
3. Await import() promise in middleware.
// server.jsconstserverBuildPromise=getServerBuildPromise()app.get('*',async(req,res,next)=>{// Ensure import('./path/to/dist/server/entry.js') has finishedawaitserverBuildPromise()// ... middleware ... (e.g. the Vike or Telefunc middleware)})functiongetServerBuildPromise(){if(process.env.NODE_ENV!=='production')returnletresolveconstserverBuildPromise=newPromise((r)=>{resolve=r})import('./path/to/dist/server/entry.js').then(()=>{resolve()})returnserverBuildPromise}
The text was updated successfully, but these errors were encountered:
brillout
changed the title
Conditionally import importBuild.cjs (not in dev but only in prod)
Conditional manual import
Apr 15, 2023
If your production and development share the same server entry file, then you need to conditionally import
dist/server/entry.js
.There are multiple approaches.
1. Top-level await.
For environments that don't support top-level await, see alternatives below.
2. Wrap entry code in async function.
3. Await
import()
promise in middleware.The text was updated successfully, but these errors were encountered: