Skip to content

Add Deno example #125

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

Closed
wants to merge 3 commits into from
Closed

Add Deno example #125

wants to merge 3 commits into from

Conversation

markmals
Copy link
Contributor

@markmals markmals commented May 8, 2025

As of version 2.2, Deno supports the requisite compilerOptions keys to enable React Router typegen types to work in Deno, so I think it's time for a Deno template! There are still a few rough edges here, but I think they're fairly low-hanging fruit to fix in the core RR codebase to make React Router an excellent choice for Deno applications. Here's what still needs work:

  • The requested module 'react-dom/server' does not provide an export named 'renderToPipeableStream'
    • react-dom/server has export shims for "node" and "edge" platforms, but renderToPipeableStream is only exported for the "node" shims. To make this work, I'm currently manually patching the react-dom/server import using sed to change it to react-dom/server.node as part of the build task pipeline. Edit: I've replaced the separate "patch-build" task in favor of a Vite resolve.alias entry.
  • Failed resolving binary export. '/Users/orion/Developer/Templates/react-router-templates/deno/node_modules/.deno/[email protected]/node_modules/react-router/package.json' did not have a bin property
    • When trying to run the React Router binary with Deno (deno run -A npm:react-router typegen), you currently get this error. To work around this, I'm running the React Router binary using its absolute path (deno run -A ./node_modules/.bin/react-router typegen).
  • I could not figure out how to pass anything besides await import("../build/server/index.js") to createDenoRequestHandler without the production build crashing. I tried passing virtual:react-router/server-build to it and that didn't work (the file runs outside of Vite). I tried passing a ServerBuild object with a getLoadContext, I tried passing the promise without awaiting it, I tried passing the promise wrapped in a function. Nothing worked, so this means no Load Context example for Deno (not sure how much this matters with middleware coming soon, which I haven't tried to make work in Deno yet).
  • Could not find package.json in react-router-templates/deno or any of its parent directories
    • A package.json file is unnecessary for this Deno setup, however without one when trying to run react-router dev it crashes.
  • Could not determine server runtime. Please install @react-router/node, or provide a custom entry.server.tsx/jsx file in your app directory.
    • If you add a package.json without specifying dependencies (since all dependencies are specified in deno.jsonc), you get this error.
  • adding isbot@5 to your package.json, you should commit this change
    • If you specify the @react-router/node dependency in package.json, then you get the this warning and react-router dev uses npm to install isbot, which has already been installed by Deno.
  • I've added a stub package.json file with the necessary package specifications to get react-router dev working without complaining, but it would be ideal to not need a package.json at all.
  • The build.target key in vite.config.ts needs to be set to "ESNext" to silence errors about top-level await.
  • The resolve.alias key in vite.config.ts needs to be manually set, because there is no tsconfig.json for vite-tsconfig-paths to operate on.

@jacob-ebey jacob-ebey mentioned this pull request May 27, 2025
@jacob-ebey
Copy link
Member

Thanks for the PR. I've simplified it a bit and got it merged here: #131

@jacob-ebey jacob-ebey closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants