Open
Description
Environment
- react-select: v5.10.1
- React Router: v7.5.3
Repro steps
- Create a React Router project per its documentation
npx create-react-router@latest router-select-repro
cd router-select-repro
npm i
npm run dev
- Confirm page renders successfully.
- Install react-select:
npm i react-select
- Add
import Select from 'react-select';
toapp/welcome/welcome.tsx
- Confirm that page no longer renders successfully, but instead shows error:
[vite] Internal server error: Cannot use import statement outside a module
Additional information
- Other packages with ES modules work correctly (tested with react-icons)
- The error appears to be related to module resolution in the Vite build system that React Router v7 uses
Related issues
A similar (possibly the same) issue was reported in #5595, and a fix was attempted in #5626, but the issue persists within React Router/vite projects.
Workaround
Importing lazily with const Select = React.lazy(() => import('react-select'));
avoids this error, but is unsatisfying as it loses type information, and likely has other implications.