Skip to content
Source
Sign inSign up
TanStack/router

notFoundError warning triggers when rendering root route #2459

Send to my agent
ClosedSzymonNadbrzezny(GitHub profile, opens in a new tab) opened this issue 11 comments

Which project does this relate to?

Start

Describe the bug

Warning about notFoundError is shown when rendering root route and there's no defaultNotFoundComponent set, even though it renders successfully.

Error message: Warning: A notFoundError was encountered on the route with ID "__root__", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (<div>Not Found<div>)

Your Example Website or App

Warning: A notFoundError was encountered on the route with ID "root", but a notFoundComponent option was not configured, nor was a router level defaultNotFoundComponent configured. Consider configuring at least one of these to avoid TanStack Router's overly generic defaultNotFoundComponent (

Not Found
)

Steps to Reproduce the Bug or Issue

  1. Clone repo and run pnpm i
  2. Run pnpm dev
  3. Go to http://localhost:3000/
  4. Warning should appear in the server logs

Expected behavior

Warning should not appear when there's no defaultNotFoundError set.

Screenshots or Videos

Image

Platform

  • OS: Windows 10
  • Browser: Arc
  • Version: Based on Chromium version 129.0.6668.71 (Official Build) (64-bit)

Additional context

Discord thread where @schiller-manuel helped me and told me to create new issue https://discord.com/channels/719702312431386674/1238170697650405547/1291393654765650033

  1. SeanCassiere added labelsbug

  2. I had that error my first time using start, and I solved it by adding the notFound component, but nevertheless it has been marked as a bug since it does seem to be one. I would like to work on that as my first contribution.

  3. @soyricardodev adding the notFoundComponent just silences this warning. however, there shouldn't even a not found error be thrown here.

  4. This is most likely caused by a missing favicon. Most modern browsers will automatically try to crawl /favicon.ico in the site, even if it's not defined in head. You can check the network tab to verify this.

    Image

    If I add a favicon.ico to public/, the error goes away

  5. I also ran into this problem while spinning up a brand new @tanstack/react-start app for the first time. I tried adding a favicon.ico but not only did that not fix anything, but the browser was not requesting the file in the first place.

    Eventually I noticed some $undefined strings in the console from the "Injected From Server" logs. I closed the window and opened it again and noticed the notFoundError went away! Hooray!

    And then I opened DevTools again and the warning came back.

    Its almost like DevTools is requesting something from the server but there is nothing in the Network Tab that indicates a 4xx error and its unclear why any console statements would be making extra requests to the server.

    I realize this is probably a react-start issue at this point, but sharing this here anyway in case someone else has the same problem.

    Any thoughts on how to fix this?

    EDIT:

    I added a defaultNotFoundComponent and dumped the output of useMatches and this is what it contained:

    {
      matches: [
        {
          id: '__root__',
          index: 0,
          routeId: '__root__',
          params: {},
          _strictParams: {},
          pathname: '/',
          updatedAt: 1749793758690,
          search: {},
          _strictSearch: {},
          searchError: undefined,
          status: 'success',
          isFetching: false,
          error: undefined,
          paramsError: undefined,
          __routeContext: {},
          __beforeLoadContext: {},
          context: {},
          abortController: AbortController {},
          fetchCount: 1,
          cause: 'enter',
          loaderDeps: '',
          invalid: false,
          preload: false,
          links: undefined,
          scripts: undefined,
          headScripts: undefined,
          meta: [Array],
          staticData: {},
          loadPromise: [Promise],
          fullPath: '/',
          globalNotFound: true,
          beforeLoadPromise: undefined,
          pendingTimeout: undefined,
          loaderPromise: undefined,
          headers: undefined
        }
      ]
    }

    Does this mean that root route itself is causing a 404 and only when DevTools are open? 🤔

    For clarity, I only have one route (following the tutorial here)

  6. @dlindahl That must be the new /.well-known/appspecific/com.chrome.devtools.json file from a recent update in Chrome Devtools, which triggers a request to that file whenever you open devtools but it won't show up in the network tab.

    See:

  7. I just ran into the same situation; no error in my logs until I open the network tab. Is there something to do to stop vite from throwing the error?

  8. That must be the new /.well-known/appspecific/com.chrome.devtools.json file from a recent update in Chrome Devtools, which triggers a request to that file whenever you open devtools but it won't show up in the network tab.

    As far as I can tell, this is the root cause (assuming there are no other issues in the Network tab). You can verify it by seeing that the warning only appears when the dev tools are opened.

    Adding the Vite plugin linked makes the warning disappear, but ultimately, the warning itself is harmless.

  9. Just created new blank app using cli, the warning still persists when dev tools are closed, and I am using Safari. Favicon present. In network tab all responses show HTTP 200 except one HTTP 101 which is WebSocket connection request.

    Added default not found component and console log to it, and it is logged every time I refresh the main page.

    Using this not found component:

        defaultNotFoundComponent: () => {
          console.log(captureOwnerStack())
          return <div>Not Found</div>
        },

    Here is the stack trace:

    LOG /src/router.tsx:15:7 - http://localhost:3000/__tsd/open-source?source=%2Fsrc%2Frouter.tsx%3A15%3A7
     →  
        at renderRouteNotFound (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/renderRouteNotFound.js:7:30)
        at OutletImpl (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Match.js:222:12)
        at file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Match.js:144:28
        at Object.useMemo (/Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/react-dom@19.2.4_react@19.2.4/node_modules/react-dom/cjs/react-dom-server.node.development.js:4027:20)
        at process.env.NODE_ENV.exports.useMemo (/Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/react@19.2.4/node_modules/react/cjs/react.development.js:1251:34)
        at MatchInnerImpl (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Match.js:139:21)
        at MatchImpl (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Match.js:74:205)
        at MatchesInner (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Matches.js:35:52)
        at Matches (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/Matches.js:21:21)
        at RouterProvider (file:///Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-router@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-router/dist/esm/RouterProvider.js:27:98)
        at StartServer (/Users/vpetryniak/ts-projects/repros/start-test/node_modules/.pnpm/@tanstack+react-start-server@1.162.2_react-dom@19.2.4_react@19.2.4__react@19.2.4/node_modules/@tanstack/react-start-server/dist/esm/StartServer.js:9:55)
  10. @valerii15298 this originates from tanstack DevTools. can you please create an issue there?

  11. why it closed? warning still logs in terminal

  12. Here's how I fixed the error I was getting. First on how to verify you are facing the error same as me and not anything else is to define defaultNotFoundComponent in your router.tsx like this:

        defaultNotFoundComponent: () => {
          console.log("[router] defaultNotFoundComponent", router.state.location.pathname);
          console.log(captureOwnerStack());
          return (
            <div>
              <p>Not found!</p>
              <Link to="/">Go home</Link>
            </div>
          );
        },

    Then you will get this error in your console:

    LOG /src/router.tsx:13:7
     →  [router] defaultNotFoundComponent /.well-known/appspecific/com.chrome.devtools.json
     →
        at renderRouteNotFound (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/renderRouteNotFound.js:16:71)
        at OutletImpl (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Match.js:180:35)
        at file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Match.js:116:26
        at Object.useMemo (/your/prj/node_modules/.bun/react-dom@19.2.4+b1ab299f0a400331/node_modules/react-dom/cjs/react-dom-server.node.development.js:4027:20)
        at process.env.NODE_ENV.exports.useMemo (/your/prj/node_modules/.bun/react@19.2.4/node_modules/react/cjs/react.development.js:1251:34)
        at MatchInnerImpl (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Match.js:113:22)
        at MatchImpl (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Match.js:64:27)
        at MatchesInner (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Matches.js:34:51)
        at Matches (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/Matches.js:24:103)
        at RouterProvider (file:///your/prj/node_modules/.bun/@tanstack+react-router@1.167.4+bf16f8eded5e12ee/node_modules/@tanstack/react-router/dist/esm/RouterProvider.js:39:29)
        at StartServer (/your/prj/node_modules/.bun/@tanstack+react-start-server@1.166.13+7393cdcbeb58a23b/node_modules/@tanstack/react-start-server/dist/esm/StartServer.js:12:54)
    LOG /src/router.tsx:14:7

    As you notice if you are using Chrome it tries to hit the Chrome devtools path to get a unique ID about your app. You can handle this in your dev environment by using vite-plugin-devtools-json. Configure the plugin as suggested in its docs and kiss the warning a goodbye!

Sign in to join this conversation.