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
In the StackBlitz, I'd expect that all imports of foo-service would resolve to the same memory reference.
Actual Behavior
When importing the same module in express code and in Remix code, the module gets loaded "twice" (once the actual module, and the other is its copy bundled in build/server/index.js)
I tried using ssr.external but that doesn't seem to work with relative files, only node_modules?
With the classic compiler, I was able to work by using the server option in remix.config.js, but I can't find a way to that with Vite (I'm not well versed with Vite's options though). If there's any workaround to this problem I'd appreciate. Otherwise, I won't be able to use the new Vite compiler at all in my projects
The text was updated successfully, but these errors were encountered:
Interesting. Yeah, I thought that importing directly from app/services from my server file would work, but you're right. The generated build/server/index.js file contains a copy of the imported code.
Anyway, I played around with a bunch of Vite and esbuild flags, but never could get them to combine since they're not built together.
So I got the crazy idea of simply having Remix import my Express server file directly. My server file actually exports the express app (for use in my Vite plugin)
// app/entry.server.tsximportappfrom"#server/index";// import the created express appexport{app}// rest of entry.server.tsx
Had Remix build the production file and sure enough, the generated file included both my Express code and the Remix stuff.
Ran NODE_ENV=production node ./build/server/remix.js
I'm not sure there's anything in Remix side that could be done to make this better, at least make sure the build file won't change too much in the future (but if it does change, that would be easy to catch in dev because it will fail fast). Either way, I do think this is a reasonable workflow and should be supported by Remix somehow.
PS: One thing I noticed is that the server build file exports some of my components and hooks. I could not understand why that happens, but got worried I could get a name conflict with the app in entry.server.tsx
Reproduction
https://stackblitz.com/edit/remix-run-remix-muutqq?file=server.js,app%2Froutes%2F_index.tsx
Check
server.js
androutes/_index.tsx
(there are comments indicating where).System Info
Used Package Manager
npm
Expected Behavior
In the StackBlitz, I'd expect that all imports of
foo-service
would resolve to the same memory reference.Actual Behavior
When importing the same module in express code and in Remix code, the module gets loaded "twice" (once the actual module, and the other is its copy bundled in
build/server/index.js
)I tried using
ssr.external
but that doesn't seem to work with relative files, only node_modules?With the classic compiler, I was able to work by using the
server
option in remix.config.js, but I can't find a way to that with Vite (I'm not well versed with Vite's options though). If there's any workaround to this problem I'd appreciate. Otherwise, I won't be able to use the new Vite compiler at all in my projectsThe text was updated successfully, but these errors were encountered: