Skip to content

Vite Plugin: route-exports plugin causes ReferenceError when used with pre-processing plugins #14374

@lionelhorn

Description

@lionelhorn

Reproduction

Go to https://stackblitz.com/edit/github-5abkxfjb?file=package.json,vite.config.ts

Image

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (4) x64 AMD Ryzen 9 7950X 16-Core Processor            
    Memory: 9.92 GB / 24.41 GB
  Binaries:
    Node: 22.19.0 - C:\nvm4w\nodejs\node.EXE
    npm: 10.9.3 - C:\nvm4w\nodejs\npm.CMD
    pnpm: 10.17.1 - C:\nvm4w\nodejs\pnpm.CMD
  Browsers:
    Edge: Chromium (140.0.3485.81)
    Internet Explorer: 11.0.22621.352

Used Package Manager

pnpm

Expected Behavior

App to properly load without errors.

Actual Behavior

In the react router repro, I added Deepkit

The Deepkit framework uses a Vite plugin to transform code to add runtime type metadata to various declarations. This is done by assigning a __type property to the exported entity, whether it's a function, variable, or another type of declaration. This transformation is crucial for Deepkit's dependency injection and reflection capabilities.

The issue

The Deepkit plugin is marked with enforce: 'pre' in Vite, ensuring it runs on the source code before other major transformations.

Transformation steps
Original + deepkit type plugin
Image

Then react-router:route-exports vite plugin then also transforms the code.
When transforming the App function, it doesn't pay attention to the App.___type declaration resulting in a ReferenceError

Image Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions