@netlify/vite-plugin-react-router couldn't complete build process with react-router v7

Hi,

I have been trying all sorts of solutions to get my deployment working locally and on the Netlify domain, but the build failed to complete the build process.

DOMAIN: https://analytics-logging.netlify.app/
NODE-VERSION: v20.19.2

Error Below:

Jun 27, 10:23:56 PM: 4259141a INFO   [GET] https://685f0bc37c59840008a9f9ef--analytics-logging.netlify.app/
Jun 27, 10:23:56 PM: 4259141a ERROR  TypeError: Cannot read properties of undefined (reading 'manifestPath')
    at requestHandler (/var/task/node_modules/@netlify/vite-plugin-react-router/node_modules/react-router/dist/development/index.js:11020:29)
    at Module.<anonymous> (file:///var/task/node_modules/@netlify/vite-plugin-react-router/dist/index.mjs:14:30)
    at async bm (file:///var/task/___netlify-bootstrap.mjs:3:109468)
    at async Runtime.handler (file:///var/task/___netlify-bootstrap.mjs:3:109139)
    at async Runtime.handleOnceStreaming (file:///var/runtime/index.mjs:1238:26)

The page keeps showing an Internal error on https://analytics-logging.netlify.app/

On my local machine, I can see this error below.

Netlify Build Complete                                        
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
โ€‹
(Netlify Build completed in 3.7s)

โฌฅ Static server listening to 3999

   โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€ โฌฅ  โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
   โ”‚                                                   โ”‚
   โ”‚   Local dev server ready: http://localhost:8888   โ”‚
   โ”‚                                                   โ”‚
   โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ

Request from ::1: GET /

โฌฅ Function react-router-server has returned an error: Cannot find module '/Users/xxx/Documents/analytics/.netlify/functions-serve/.unzipped/react-router-server/node_modules/react-router/dist/development/index.mjs' imported from /Users/xxx/Documents/analytics/.netlify/functions-serve/.unzipped/react-router-server/.netlify/v1/functions/react-router-server.mjs

hey @abisalde thanks for getting in touch! Keep in mind as well that if it doesnโ€™t build locally, it will not build on Netlify.

Can you confirm that after installing the plugin, you adjusted your vite.config.ts file as mentioned in the docs here? React Router on Netlify | Netlify Docs

Hi @marcus.little :waving_hand:,

Yes, I did. I followed the docs to the later and did the same for the template providing by react-router team for Netlify and got the same error as mine.

I logged an issue on GitHub here. Netlify failed to start production build using netlify template or @netlify/vite-plugin-react-router with V7 Framework mode ยท Issue #135 ยท remix-run/react-router-templates ยท GitHub

Thank you for reaching out

thanks for following up and opening that issue! Iโ€™m wondering if the issue is that you still need to run the remix.init script. When you install deps with npm via npx create-remix@latest, youโ€™re prompted to run the script during setup:

  deps   Install dependencies with npm?
         Yes

  init   This template has a remix.init script. Do you want to run it?
         Yes

      โœ”  Dependencies installed
      โœ”  Dependencies for remix.init script installed

      โ—ผ  Running template's remix.init script... 

However when opting out (to instead use yarn), this step gets skipped, although youโ€™d still need to run the script manually:

  deps   Install dependencies with npm?
         No
      โ—ผ  Skipping install step. Remember to install dependencies after setup with npm install.

      โœ”  Git initialized

      โ—ผ  Skipping template's remix.init script. After installing dependencies, you can run the script in the remix.init directory with npx remix init.

Can you let me know if you completed that step as well? When going through this setup and installing the script, Iโ€™m able to get the home page to render properly:

ok I got it, have you done this before ?

Hi @marcus.little ,

I am not using Remix but I am using Vite-config and I followed through with npx create-react-router@latest and following the prompt as shown on the terminal

hey @abisalde thanks again for following up on this, and apologies for the misunderstanding there. If youโ€™re looking to just run straight React Router, Iโ€™d still recommend Netlifyโ€™s own internal docs: React Router on Netlify | Netlify Docs

  1. scaffold the project npx create-react-router@latest --template netlify/react-router-template
  2. install the dependencies yarn
  3. yarn run dev

let me know if this helps!

Hi Marcus, when you use the netlify/react-router-template, the start command runs npm run dev. The start command should serve the built files (which is the original issue of this thread), rather than running the dev server

Iโ€™m trying to debug a production-specific issue, so I need a better environment to test the built files. The behavior of Vite varies significantly between development and production. Additionally, Netlify wraps everything in a server function for production, making npm run dev far from ideal for debugging

Also, the docs are pretty sparse right now, mostly just a command to run. It would be awesome to have more detailed documentation for react-router v7

Hi @marcus.little

This is a development setup you have done, The issue is about setting up production build which I did with the template just like this npx create-react-router@latest --template netlify/react-router-template.

Please, can you try with npx netlify serve for production build?

Thanks for following up on this, and apologies for the delay! Iโ€™ve since replicated and escalated this issue internally, weโ€™ll follow up again here as soon as we have the next steps.

1 Like

As stated in the issue cited below, this is an issue with Nodeโ€™s module resolution and probably needs to have a change to the React Router Vite plugin for Netlify.

Here is an issue with a fix: template doesn't run on fresh clone ยท Issue #10 ยท netlify/react-router-template ยท GitHub

Hi folks!

Thank you for reporting this and sorry for the delay here. This was a weird one!

Iโ€™ve released a fix to netlify-cli: Release v23.9.4 ยท netlify/cli ยท GitHub.

This reproduces the issue:

npx -y netlify@23.9.3 serve

while this works as expected:

npx -y netlify@23.9.4 serve

Hope this helps!

1 Like