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

404 Not Found with useFetcher in only local #40

Closed
Code-Hex opened this issue Nov 30, 2024 · 3 comments · Fixed by #41
Closed

404 Not Found with useFetcher in only local #40

Code-Hex opened this issue Nov 30, 2024 · 3 comments · Fixed by #41

Comments

@Code-Hex
Copy link

Code-Hex commented Nov 30, 2024

Only in the local environment, a request using useFetcher to a resource route that only defines a loader will result in a 404 Not Found.

No error:

  • hono-remix-adapter is not used.
  • production build and hono-remix-adapter is used.
Error: No route matches URL "/src/app/routes/user.tsx"
    at getInternalRouterError (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/router/router.ts:5505:5)
    at Object.query (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/router/router.ts:3527:19)
    at handleDocumentRequest (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/server-runtime/dist/server.js:275:35)
    at requestHandler (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/server-runtime/dist/server.js:160:24)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)
    at getRequestListener.overrideGlobalObjects (file:///Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@hono/vite-dev-server/dist/dev-server.js:93:32)
    at responseViaResponseObject (file:///Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@hono/node-server/dist/index.mjs:333:15)
No routes matched location "/src/app/routes/user.tsx?import"
ErrorResponseImpl {
  status: 404,
  statusText: 'Not Found',
  internal: true,
  data: 'Error: No route matches URL "/src/app/routes/user.tsx"',
  error: Error: No route matches URL "/src/app/routes/user.tsx"
      at getInternalRouterError (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/router/router.ts:5505:5)
      at Object.query (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/router/router.ts:3527:19)
      at handleDocumentRequest (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/server-runtime/dist/server.js:275:35)
      at requestHandler (/Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@remix-run/server-runtime/dist/server.js:160:24)
      at processTicksAndRejections (node:internal/process/task_queues:95:5)
      at getRequestListener.overrideGlobalObjects (file:///Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@hono/vite-dev-server/dist/dev-server.js:93:32)
      at responseViaResponseObject (file:///Users/codehex/go/src/github.com/Code-Hex/remix-test-fetch/node_modules/@hono/node-server/dist/index.mjs:333:15)
}

I have reproduction code for this:

https://github.com/Code-Hex/remix-test-fetch

@Code-Hex Code-Hex changed the title 404 Not Found 404 Not Found with useFetcher in only dev Nov 30, 2024
@Code-Hex Code-Hex changed the title 404 Not Found with useFetcher in only dev 404 Not Found with useFetcher in only local Nov 30, 2024
@Code-Hex
Copy link
Author

Oh, I have probably found a solution, but I honestly don't know why this works.

diff --git a/vite.config.ts b/vite.config.ts
index 14620e0..2c2f3be 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -7,6 +7,7 @@ import tsconfigPaths from "vite-tsconfig-paths";
 import serverAdapter from "hono-remix-adapter/vite";
 import { getLoadContext } from "./src/load-context";
 import adapter from "@hono/vite-dev-server/cloudflare";
+import { defaultOptions } from "@hono/vite-dev-server";

 declare module "@remix-run/node" {
   interface Future {
@@ -31,6 +32,12 @@ export default defineConfig({
       adapter,
       getLoadContext,
       entry: "src/api/index.ts",
+      exclude: [
+        ...defaultOptions.exclude,
+        "/assets/**",
+        "/app/**",
+        "/src/app/**",
+      ],
     }),
     tsconfigPaths(),
   ],

If this was the intended specification for hono-remix-adapter and not a particular problem, it could be closed.

@yusukebe
Copy link
Owner

yusukebe commented Dec 2, 2024

Hi @Code-Hex

This is not a bug, so you can resolve the issue with the setting as you showed. But it's not helpful, so I've added the change to exclude /src/app/** by default. #41 With the new version, you don't have to change the setting to vite.config.ts.

@Code-Hex
Copy link
Author

Code-Hex commented Dec 2, 2024

@yusukebe Thank you so much!

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 a pull request may close this issue.

2 participants