-
-
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
Bug with resolving imports when using viteServer.ssrLoadModule in astro adapter #11048
Comments
The bug is that as you're calling I'm not really sure how we can fix this on the Vite side, perhaps it's not safe to call |
Thanks a lot ! That fixed the issue. Is there any place for discussion around better support for a dev server in adapter? There was this stream where they explored it but nothing came out of this |
Also a question is, why does it happen only with astro and not in a vite project |
For this specific case, I don't think there's a discussion about this yet. For adapter influencing dev in general, there's the Vite 6 Environment API, but it wouldn't help this case with a custom express/fastify server. I've not seen the pattern you showed a lot in the wild, and it feels a bit hacky to me though.
It also happens with a Vite project if you do the Also closing this for now since it's not a bug in Astro. I agree that the error is confusing and perhaps you can submit an issue to Vite about it, but I'm not sure how to fix this in Vite yet in the meantime. |
Ah, understood what I was missing and why this worked in the vite example I gave above.
I admit this is a rare use case, but super important when you want APIs/business logic separated from your rendering framework. This has helped that we have APIs fully separated from next and can move to astro without rethinking our that whole layer. Anyway, thanks for the help! |
Ah I missed the Vite example you gave. Yeah the difference is that the example calls |
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
I am migrating from nextjs to astro at work and need to run astro server under a express server as we have integrations on express level want to be using them.
I created a express adapter based on https://github.com/matthewp/astro-fastify but both of these have the same issue which is in the vite plugin's
configureServer
function. we get the vite server and have to load our server file withserver.ssrLoadModule
.This
server.ssrLoadModule
function is not resolving relative imports correctly in astro projects, it works fine when used in a vanilla vite project (Example).Both projects have the same file structure for server folder
The following error is thrown when trying to import
./utils/index.js
inserver/index.js
Related
matthewp/astro-fastify#21
What's the expected result?
The relative imports should work as expected
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-kfswv5?file=astro-express%2Findex.js
Participation
The text was updated successfully, but these errors were encountered: