Skip to content

Middleware types not working with NodeNext resolution #13375

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
pawelblaszczyk5 opened this issue Apr 6, 2025 · 5 comments
Open

Middleware types not working with NodeNext resolution #13375

pawelblaszczyk5 opened this issue Apr 6, 2025 · 5 comments

Comments

@pawelblaszczyk5
Copy link

pawelblaszczyk5 commented Apr 6, 2025

I'm using React Router as a...

framework

Reproduction

https://github.com/pawelblaszczyk5/invalid-new-middleware-types-node-next

  1. Go to app/routes/home.tsx
  2. Observe context being typed incorrectly despite middleware being enabled and global type augmentation done

Image

Image

I think that's similar cause as this - #12715

If you change the module resolution to e.g. Bundler it will work properly.

System Info

System:
    OS: macOS 15.3.2
    CPU: (8) arm64 Apple M1 Pro
    Memory: 406.81 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.10.0 - ~/.local/state/fnm_multishells/3848_1743953207334/bin/node
    Yarn: 1.22.19 - ~/.local/state/fnm_multishells/3848_1743953207334/bin/yarn
    npm: 10.2.3 - ~/.local/state/fnm_multishells/3848_1743953207334/bin/npm
    pnpm: 8.15.8 - ~/.local/state/fnm_multishells/3848_1743953207334/bin/pnpm
    bun: 1.1.33 - ~/.bun/bin/bun
  Browsers:
    Chrome: 134.0.6998.166
    Edge: 120.0.2210.121
    Safari: 18.3.1
  npmPackages:
    @react-router/dev: ^7.5.0 => 7.5.0 
    @react-router/node: ^7.5.0 => 7.5.0 
    @react-router/serve: ^7.5.0 => 7.5.0 
    react-router: ^7.5.0 => 7.5.0 
    vite: ^5.4.11 => 5.4.17

Used Package Manager

pnpm

Expected Behavior

context parameter is properly typed due to augmentation in react-router.config.ts

Actual Behavior

context is incorrectly typed (still AppLoadContext) when using NodeNext

@pawelblaszczyk5 pawelblaszczyk5 changed the title Experimental middleware types not working with NodeNext resolution Middleware types not working with NodeNext resolution Apr 6, 2025
@shmuli9
Copy link

shmuli9 commented Apr 17, 2025

I am seeing the same issue but I am using the bundler option in my tsconfig

Possibly this is addressed by #13381

@pawelblaszczyk5
Copy link
Author

I am seeing the same issue but I am using the bundler option in my tsconfig

Possibly this is addressed by #13381

The linked issue is different one, that impacts that some types didn’t use the future flag branching. This issue is that this branching isn’t respected in some parts of code when using specific resolution 😃

@shmuli9
Copy link

shmuli9 commented Apr 17, 2025

The linked issue is different one, that impacts that some types didn’t use the future flag branching. This issue is that this branching isn’t respected in some parts of code when using specific resolution 😃

Ye, I tested with 7.5.1-pre.0 and it didn't resolve the issue. That being said, I am not getting the correct types even when using the bundler tsconfig

@pawelblaszczyk5
Copy link
Author

I’m pretty sure it should work. Do you have some reproduction? Did you enable the type level feature flag and the file is in the same TS project in case you use references?

@shmuli9
Copy link

shmuli9 commented Apr 17, 2025

Thanks - I am using the cloudflare template and it uses tsconfig projects.
For some reason they didn't include react-router.config.ts in the tsconfig so my type augmentation wasn't being picked up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants