Skip to content

SPA Mode not working with serverModuleFormat: cjs #12462

@krsilas

Description

@krsilas

I'm using React Router as a...

framework

Reproduction

  • Go to https://stackblitz.com/edit/stackblitz-starters-6zkc9f?file=react-router.config.ts
  • If dev server starts automatically, stop the dev server
  • Run pnpm run build -> build/client/index.html is generated as part of build because of ssr: false
  • Enable serverModuleFormat: "cjs" in react-router.config.ts
    (because even though the server build is deleted after running the build in ssr: false, ssr is used for initial prerendering and some third party libraries don't have good esm support)
  • Run pnpm run build again -> Error:
    [react-router] exports is not defined in ES module scope
    This file is being treated as an ES module because it has a '.js' file extension and '/home/projects/stackblitz-starters-6zkc9f/package.json' contains "type": "module". To treat it as a CommonJS script, rename it to use the '.cjs' file extension.
  • Rename react router config to react-router.config.cjs
  • Run pnpm run build again

System Info

See stackblitz environment

Used Package Manager

pnpm

Expected Behavior

When config contains ssr: false and serverModuleFormat: "cjs", the build does not fail and renders static html.

Actual Behavior

Error instructs to rename config to react-router.config.cjs but .cjs file is ignored and default config is being used -> ssr: true.

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