Skip to content

bug: TypeError for 'path' argument (received undefined) in react-router-serve due to undefined build.publicPath #13484

@DavidGutierrez94

Description

@DavidGutierrez94

I'm using React Router as a...

framework

Reproduction

Bug Description:

When attempting to run a React application built with using react-router-serve, the server fails to start, throwing a TypeError. The error message indicates that a 'path' argument expected a string but received undefined.

Further investigation : I'm using trading view advanced charting library which requres to have the lib files on the public folder to be able to load the chart widgets.This suggests this is caused by react-router-serve being unable to resolve the build.publicPath (or equivalent like Vite's base) from the project's build configuration. This prevents the server from correctly determining asset paths and/or handling SPA routing fallbacks.

Steps to Reproduce:

I have to setup a minified version of the project to share in a public repo

  1. Install the project using Bun
  2. Run the build script
  3. Run the start script

Disclaimer: I'm using Bun as package manager

System Info

System:
    OS: macOS 15.4.1
    CPU: (10) arm64 Apple M4
    Memory: 74.66 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 22.5.0 - ~/.nvm/versions/node/v22.5.0/bin/node
    Yarn: 1.22.22 - /opt/homebrew/bin/yarn
    npm: 10.8.2 - ~/.nvm/versions/node/v22.5.0/bin/npm
    bun: 1.2.10 - /opt/homebrew/bin/bun
  Browsers:
    Chrome: 135.0.7049.115
    Safari: 18.4
  npmPackages:
    @react-router/dev: ^7.5.2 => 7.5.2 
    @react-router/node: ^7.5.2 => 7.5.2 
    @react-router/serve: ^7.5.2 => 7.5.2 
    react-router: ^7.5.2 => 7.5.2 
    vite: ^6.3.3 => 6.3.3

Used Package Manager

npm

Expected Behavior

react-router-serve should start successfully, serve the application from the specified build.publicPath (e.g., http://localhost:port/subfolder/), and correctly handle client-side routing for deep links and page refreshes.

Actual Behavior

react-router-serve crashes immediately upon starting with the following error:

bun --bun run start
$ react-router-serve ./build/server/index.js
90 |   };
91 |   let app = (0, import_express2.default)();
92 |   app.disable("x-powered-by");
93 |   app.use((0, import_compression.default)());
94 |   app.use(
95 |     import_node_path.default.posix.join(build.publicPath, "assets"),
                                        ^
TypeError: The "paths[0]" property must be of type string, got undefined
 code: "ERR_INVALID_ARG_TYPE"

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions