Sign in
Log inSign up
Cathal Mac Donnacha

168 likes

·

121.1K reads

42 comments

Tayo Ishola
Tayo Ishola
Sep 24, 2022

Great article

I think you should update jsx key of tsconfig.json to

"jsx": "react-jsx"

to prevent typescript errors like

'React' refers to a UMD global, but the current file is a module. Consider adding an import instead.

2
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Sep 27, 2022

Updated, thank you for that. 🙏

·
Matthew Beadlecomb
Matthew Beadlecomb
Nov 16, 2022

Thank you so much for this easy to follow post. I had been wanting to make the switch from CRA to Vite for a while but I was worried it would take me a long time. After reading your article I made the switch in about 3 hours!!

2
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Nov 16, 2022

Great to hear Matthew! Glad you found the article useful.

·
Malin Hanák
Malin Hanák
Feb 16, 2023

This was a great article, I read it because I wanted to know about this migration as it very relevant my my work place and it up fixing and completely different vite issue I have had for weeks, with the resolve.alias config! AMAZING

2
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Feb 16, 2023

Great to hear it helped Malin. 👍

·
Jan Paepke
Jan Paepke
Mar 29, 2023

Just followed your guide to sucessfully migrate to vite. It's so fast and I'm really happy to finally have gotten rid of cra. (not being able to update to ts5 was the final straw).

Here's a tipp though: Vite recommends using vite-plugin-checker for checking types. I also added it and it works great. This removes your only "disadvantage".

2
·
·3 replies
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Mar 29, 2023

Excellent thanks. This wasn't available at the time of writing so happy to see that!

·
Josh Schneider
Josh Schneider
Mar 31, 2023

Cathal Mac Donnacha, I just found the same thing after searching around Vite docs. Maybe you could just update your post to mention it? Thanks for the helpful post!

·
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Apr 11, 2023

Thanks Jan Paepke. I still see it as a disadvantage since it's not built into Vite itself. However, I've mentioned it as an option. 👍

·
Yagnesh Virani
Yagnesh Virani
Apr 11, 2023

10/10 hearts! Worked flawlessly. Migrated Refine app from CRA to Vite.

Updated scripts to - { "start": "refine run vite", "build": "tsc && refine run vite build", "serve": "refine run vite preview", "refine": "refine" }

Thereafter npm start did show empty white page for a long time but soon after the content displayed

2
·
Rob van der Leek
Rob van der Leek
Aug 21, 2023

Excellent migration guide from CRA to Vite 👌

2
·
Andrew Baisden
Andrew Baisden
Sep 10, 2022

Awesome, I also made the switch from CRA. Now I am using Next.js and Vite.

1
·
Freddie
Freddie
Oct 24, 2022

Worked wonders, thanks!

1
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Oct 24, 2022

Glad you found it useful Freddie.

·
Bob O'Toole
Bob O'Toole
Dec 6, 2022

nice! now my homepage won't render and i f*ed up my whole app!

1
·
·1 reply
Bob O'Toole
Bob O'Toole
Dec 6, 2022

lol jk. got it working. thanks!

1
·
Paul Derbyshire
Paul Derbyshire
Feb 8, 2023

very useful, I switched from CRA too and already seeing the benefits

1
·
Alex Sweeney
Alex Sweeney
Feb 18, 2023

This is probably a long shot, but do you know why my page is totally blank now? There's no content in the root div, almost no console logs, and no network activity.

1
·
·4 replies
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Feb 18, 2023

I'm afraid I wouldn't be able to help without looking at the project. Is it open source?

·
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Feb 18, 2023

Have you tried #3 under the Troubleshooting section?

1
·
Alex Sweeney
Alex Sweeney
Feb 18, 2023

Cathal Mac Donnacha Yep, and I know that worked because I can see the root div, there's just nothing in it. IntelliJ also isn't happy about the /src/index.tsx, it thinks it doesn't exist and I think it's trying to look from the public folder. IntelliJ stops complaining when I change it to src/index.tsx, but the page is still blank. Also the link you added to the troubleshooting docs is broken. Our app is not open source and I can't make it open source :/ I knew this might be a long shot, but its hard to debug when there's no error messages or anything...

1
·
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Feb 24, 2023

Alex Sweeney No worries. I updating the link to the troubleshooting docs, thanks for that!

·
Dhruv Khandelwalal
Dhruv Khandelwalal
May 26, 2023

I am getting a blank screen after running yarn run dev. I moved my index.html to the root of the folder and added the script but nothing is working.

1
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Oct 29, 2023

Hey Dhruv, did you manage to get this working?

·
Deactivated User
Deactivated User
Deactivated User
Jun 5, 2023

Great article! The only think that kept it from working after following this guide was lack of proxying, which can easily be added in defineConfig. You might wanna add something about this since I assume(?) most people use it. I my case, I had to change it to this:

export default defineConfig({
  plugins: [react(), viteTsconfigPaths(), svgrPlugin()],
  server: {
    port: 3000,
    proxy: {
      "/api": {
        target: "http:[double-slash]localhost:8080",
        changeOrigin: true,
      },
      '/ws': {
        target: 'ws:[double-slash]localhostt:8080',
        ws: true,
      },
    },
  },
});

where [double-slash] is an awkward way to get around the fact that I'm not allowed to post "links".

1
·
Terence ezenyili
Terence ezenyili
Jul 1, 2023

Vite is a lot faster. 💨

1
·
Đồng Đặng Minh
Đồng Đặng Minh
Sep 28, 2023

Just note, vite-plugin-svgr package was release version 4, so if you install this version it won't work with syntax in this blog. You should downgrade to verion 3.3.0

1
·
·5 replies
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Sep 28, 2023

What syntax should be used and I can update the article?

·
Đồng Đặng Minh
Đồng Đặng Minh
Sep 29, 2023
·
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Oct 2, 2023

Đồng Đặng Minh I just updated it. Can you check if it looks ok?

·
Đồng Đặng Minh
Đồng Đặng Minh
Oct 4, 2023

Cathal Mac Donnacha Syntax is look good for library's version latest, but I don't think it will be used for most developer. So I suggest this section should be show the both syntaxs of version 3.x and 4.x

·
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Oct 4, 2023

Đồng Đặng Minh I imagine anyone migrating from CRA to Vite will be using a fresh installation of Vite, therefore picking up the latest version of svgr.

·
Francesco
Francesco
Oct 29, 2023

Great article, thank you very much! It saved me from a lot of headaches 🍻

1
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Oct 29, 2023

Great to hear Francesco!

·
Saba Kauser
Saba Kauser
Oct 18, 2024

Is there a step required if my project uses craco ?

1
·
·1 reply
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Nov 3, 2024

Sorry, I've never used craco.

·
Malin Hanák
Malin Hanák
Feb 24, 2023

I don't know if it is alright to ask questions here, but I have migrated on of my CRA's fully to vite now, following this amazing guide. But I am running into problems when it comes to building it for productions, whenever I run it in productions it cannot find the files in assets folders, it fails with 404. I think this is because the index.html script and link tags are missing a leading . to the paths but I cannot find anywhere on how to configure vite fix this issue. Have you any ideas?

·
·2 replies
Cathal Mac Donnacha
Cathal Mac Donnacha
Author
·Feb 24, 2023

Hey Malin, I think this question would be best placed on Stack Overflow as it will be difficult to help without code examples, screenshots etc.

·
Malin Hanák
Malin Hanák
Feb 27, 2023

Cathal Mac Donnacha Thank you, fully understand!

1
·