Skip to content
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

support serverModuleFormat: "cjs" #135

Closed
maggisk opened this issue Jan 16, 2024 · 6 comments
Closed

support serverModuleFormat: "cjs" #135

maggisk opened this issue Jan 16, 2024 · 6 comments
Labels
Ecosystem: Frameworks type: feature code contributing to the implementation of a feature and/or user facing functionality

Comments

@maggisk
Copy link

maggisk commented Jan 16, 2024

Is your feature request related to a problem? Please describe.

I'm trying to upgrade a project to remix version 2 that runs on netlify. It looks like it would be a huge effort to get it to run with esm module format and would therefor like to configure remix to use serverModuleFormat: "cjs".
Everything seems to work fine running locally, but I can not get it to run on netlify.

Describe the solution you'd like

Being able to set remix config to serverModuleFormat: "cjs" and deploy to netlify.

Describe alternatives you've considered

I tried creating a fresh remix project from this starter and change serverModuleFormat to cjs. It runs fine locally but on netlify the frontpage returns 404 and opening the handler directly returns an error: Runtime.HandlerNotFound - server.handler is undefined or not exported

https://bucolic-blini-fa5899.netlify.app and https://bucolic-blini-fa5899.netlify.app/.netlify/functions/server

I also attempted converting our project to esm, but I don't think that's going to happen anytime soon, so we're stuck on remix v1 at the moment

@ascorbic ascorbic added the type: feature code contributing to the implementation of a feature and/or user facing functionality label Jan 22, 2024
@ascorbic
Copy link
Member

Hi. The server module format shouldn't affect your site's module format. What happens if you try to deploy as-is, with your site in cjs and the server still as esm?

@maggisk
Copy link
Author

maggisk commented Jan 22, 2024

Do you mean using cjs for your application but set the remix config serverModuleFormat to esm?

You'd have to remove "type": "module" from package.json but the remix build would output esm module containing import statements etc that I'm not sure how to fix. I tried setting serverBuildPath: "./build/index.mjs" but netlify won't even deploy any serverless functions

I made a demo project at https://github.com/Life-Swap/remix2test with a few branches that attempt to get things working but no luck so far.

It's deployed at https://bucolic-blini-fa5899.netlify.app with branch deploys enabled

@ascorbic
Copy link
Member

If you remove "type": "module" and convert remix.config.js to cjs it should work.

@ascorbic
Copy link
Member

@maggisk
Copy link
Author

maggisk commented Jan 23, 2024

That works. Thank you.

I also had to set serverBuildPath: "./build/index.mjs" in development for the dev server to treat it as esm

@ascorbic
Copy link
Member

ascorbic commented Jan 23, 2024

Great! The dev server shouldn't be using the Netlify config unless you're deploying to edge functions, because it should be using the Remix dev server instead. That's why there's the conditional env var in the sample config

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ecosystem: Frameworks type: feature code contributing to the implementation of a feature and/or user facing functionality
Projects
None yet
Development

No branches or pull requests

2 participants