“@vitejs/plugin-react can’t detect preamble. Something is wrong.” console message with flask-vite and React

I wanted to use flask-vite to add some React components to my app.

I started by using the flask-vite Flask plugin to add Vite to my Flask project.

Then I installed React and carefully updated the configuration files, using a freshly created React project that I made with Vite as a reference.

I couldn’t get my React components to show up, and the only clue was this console message:

@vitejs/plugin-react can't detect preamble. Something is wrong.

I searched for this message and found lots of pages that weren’t very helpful.