frandiox / vite-ssr

Use Vite for server side rendering in Node
MIT License
823 stars 91 forks source link

__DEV__ Vite config define breaks @elastic/apm-rum-core. #221

Closed phlegx closed 3 weeks ago

phlegx commented 4 months ago

Hi!

Using the following code in plugins.ts breaks @elastic/apm-rum-core package:

define: {
 ...
  __DEV__: env.mode !== 'production',
},

See @elastic/apm-agent-rum-js/issues/1372

Maybe using a more package specific naming like __VITE_SSR_DEV__ could be very useful.

briangleeson commented 1 month ago

I've just encountered this problem as well with another package, resulting in this build error:

[commonjs--resolver] Unexpected keyword 'false' (55:5) in C:/Snaps/pwp/pwp-ui/node_modules/@carbon/react/es/components/ModalWrapper/ModalWrapper.js
file: node_modules/@carbon/react/es/components/ModalWrapper/ModalWrapper.js:55:5
55:   if(false) {
         ^

The false on line 55 should be __DEV__

The vite-ssr code mentions that this is a workaround for a bug in Vite v2.6.0: https://github.com/frandiox/vite-ssr/blob/650435fc9e6104b998cb261c574037228e9add64/src/plugin.ts#L34 Seems like that bug was fixed in v2.8.0? https://github.com/vitejs/vite/pull/5515

FYI We're curently using Vite v4.5.3

briangleeson commented 1 month ago

Tested out @phlegx's suggestion by manually updating the __DEV__ references in node_modules/vite-ssr to use __VITE_SSR_DEV__ instead, and the problem is solved. Is this an acceptable solution @frandiox? I can cut a PR for this, as we need this fix

briangleeson commented 1 month ago

PR opened: https://github.com/frandiox/vite-ssr/pull/222

briangleeson commented 1 month ago

No response from the repo owner after pinging them in this ticket, via their personal website, and via DM on twitter. Not sure what we can do here if the owner is unavailable. The last commit that was merged was over a year ago, has this repo/project been abandoned?

phlegx commented 3 weeks ago

thx @frandiox! :muscle:

frandiox commented 3 weeks ago

Should be released in 0.17.2, sorry for the delay!

phlegx commented 3 weeks ago

Don't worry! The important thing is to keep going.

PR teleport and unhead are also important. Please take a look on it!