question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

loadDistEntries error in prod build after upgrading from v0.3 to v0.4

See original GitHub issue

Description

After upgrading from v0.3.64 to v0.4.19, I followed the migration guide to get the dev environment up and running (and it’s working great - in particular, fixes a FOUC issue that I used to see on every page load in the dev environment, so very excited about being able to use the new version!). However, when testing the production build, I run into this issue on the first page request:

[15:49:04.924] INFO: Server running at http://0.0.0.0:3000
::ffff:127.0.0.1 - - [12/Aug/2022:03:49:11 +0000] "GET /api/auth/session HTTP/1.1" 200 2 "-" "undici"
Error: [vite-plugin-ssr@0.4.19][Bug] You stumbled upon a bug in vite-plugin-ssr's source code. Reach out at https://github.com/brillout/vite-plugin-ssr/issues/new or https://discord.com/invite/qTq92FQzKb and include this error stack (the error stack is usually enough to fix the problem). A maintainer will fix the bug (usually under 24 hours). Do not hesitate to reach out as it makes vite-plugin-ssr more robust. Debug info (this is for the vite-plugin-ssr maintainers; you can ignore this): `{"entryFile":"/app/node_modules/vite-plugin-dist-importer/dist/autoImporter.js"}`.
    at loadDistEntries (/app/node_modules/vite-plugin-ssr/dist/cjs/node/plugin/plugins/distEntries/loadDistEntries.js:16:28)
    at getGlobalContext (/app/node_modules/vite-plugin-ssr/dist/cjs/node/globalContext.js:26:29)
    at initializePageContext (/app/node_modules/vite-plugin-ssr/dist/cjs/node/renderPage.js:123:27)
    at renderPage_ (/app/node_modules/vite-plugin-ssr/dist/cjs/node/renderPage.js:30:41)
    at renderPage (/app/node_modules/vite-plugin-ssr/dist/cjs/node/renderPage.js:153:16)
    at pageHandler (/app/services/portal/backend/backend/index.ts:101:25)

The error seems to indicate that distEntries is null, so I tried following the instructions here to manually import the dist/server/importBuild.cjs file in my entrypoint, but it doesn’t seem to make a difference whether it’s there or not. My dev environment doesn’t fit any of the criteria described in #403 - it’s just plain Node 16, with npm as a package manager, although it is inside an npm workspace, so the node_modules folder (/app/node_modules) is a couple of levels up from the package directory (/app/services/portal). This is running inside a Debian Bullseye Docker dev environment. The only other possibly weird thing I’m doing is running the app using node -r esbuild-runner/register.

I added some logging to the loadDistEntries file, and I can see setDistEntries being called, but when loadDistEntries is subsequently called, distEntries is always null.

I noticed even stranger behaviour when I added the following to that same file:

setInterval(() => {
  console.log("distEntries", distEntries);
}, 1000);

It initially produces logs as follows, with a single log line per second, as expected:

distEntries null
[16:30:41.059] INFO: Server running at http://0.0.0.0:3000
distEntries null
distEntries null
distEntries null
distEntries null
...

But then as soon as I navigate to one of the pages, it produces two different log messages each second:

...
distEntries {
  pageFiles: [Function: pageFiles],
  clientManifest: [Function: clientManifest],
  pluginManifest: [Function: pluginManifest]
}
distEntries null
distEntries {
  pageFiles: [Function: pageFiles],
  clientManifest: [Function: clientManifest],
  pluginManifest: [Function: pluginManifest]
}
distEntries null
...

The null value is the one that is obviously being used when loadDistEntries is called, every time a page request is made.

I’m pretty stumped as to how this is occurring, and I feel like I’ve exhausted my understanding of the Node/Vite/VPS internals, so I’m curious if you have any insight! 😅

Error Stack

(See above)

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
brilloutcommented, Aug 13, 2022

👍 Let me know if there is anything else.

(Btw. I just created a GitHub sponsorship page in case that’s something you’d be interested in. But not worry if you don’t 😃.)

0reactions
bradchristensencommented, Aug 13, 2022

Good call! It didn’t occur to me that we could stash the distEntries in the global scope. That fixes it - thank you so much for the very speedy patch.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[Explanation] `vite-plugin-ssr` automagically loads the files ...
If we install npm packages after running $ vite build ... loadDistEntries error in prod build after upgrading from v0.3 to v0.4 #417....
Read more >
The command "npm run build -- --prod" exited with code 1 error
Perform any of the following options as long as there is an error. For passing an argument to build command: change 'npm run...
Read more >
ng build --prod error after updating to 17.1.50 | Angular
I get the following error on production build after update ... So, we suggest you update the angular dev kit version to V0.10.7 ......
Read more >
Upgrading : Error when building the project after upgrade
After an upgrade, an error is observed which prevents the project from successfully building. Steps to Reproduce. Clarifying Information.
Read more >
ng build - Angular
Option Description Value Type Default Value ‑‑aot Build using Ahead of Time compilation. boolean true ‑‑base‑href Base url for the application being built. string ‑‑delete‑output‑path Delete...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found