@vitejs/plugin-react-refresh doesn't work with generic react functional components
See original GitHub issueDescribe the bug
Generic typescript react functional components cannot be transformed using plugin-react-refresh
.
This works with the typescript compiler.
Reproduction
interface MyProps<T> {
readonly example: T;
}
export const MyComponent = <T,>({example}: MyProps<T>) => {
return null;
}
System Info
Output of npx envinfo --system --npmPackages vite,@vitejs/plugin-vue --binaries --browsers
:
System:
OS: macOS 11.0.1
CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
Memory: 833.76 MB / 32.00 GB
Shell: 5.8 - /bin/zsh
Binaries:
Node: 15.3.0 - /usr/local/bin/node
npm: 7.0.14 - /usr/local/bin/npm
Browsers:
Chrome: 89.0.4389.90
Edge: 89.0.774.57
Firefox: 86.0
Safari: 14.0.1
npmPackages:
vite: ^2.1.3 => 2.1.3
Used package manager:
Logs
10:22:21 AM [vite] hmr update /src/web/components/common/AutoComplete.tsx (x4)
10:22:21 AM [vite] Internal server error: Transform failed with 1 error:
<redacted> 25:6: error: Expected "}" but found ";"
Plugin: vite:esbuild
File: <redacted>
Expected "}" but found ";"
23 | example
24 | }: MyProps<T>) => {
25 | _s();
| ^
26 |
Before submitting the issue, please make sure you do the following
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn’t already an issue that reports the same bug to avoid creating a duplicate.
- Provide a description in this issue that describes the bug.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
@vitejs/plugin-react - npm
The all-in-one Vite plugin for React projects. enable Fast Refresh in development; use the automatic JSX runtime; avoid manual import React in ....
Read more >How to make a functional React component with generic type?
react native 's Fast Refresh did not work for that component. When the parent component is saved, it reloaded. Does anyone know why...
Read more >React Javascript - Replit
Here's a template that uses @vitejs/plugin-react and doesn't have errors when adding those two UI packages: replit.com/@phil-mac/React-Vite-Template.
Read more >jsx-sfc | Yarn - Package Manager
A SFC like React function component API for managing CSS-in-JS and static members. readme. JSX Separate Function Components.
Read more >react-dom.development.js:18687 the above error occurred in ...
As i can see in your import, You have imported useNavigate from 'react' which is wrong package. Please import from 'react-router-dom';. Open side...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@rockwotj this is an issue with babel TSX parser: https://github.com/babel/babel/issues/12978
It was also reported before here https://github.com/vitejs/vite/issues/2295
There is a workaround for this problem here https://github.com/microsoft/TypeScript/issues/15713#issuecomment-300545248
This is a limitation cased by the use of <T> for generic type parameter declarations. combined with JSX grammar, it makes such components ambiguous to parse.
Thank you @patak-js !