Skip to content
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

"can't detect preamble" error with React plugin #153

Closed
2 tasks done
mdesantis opened this issue Dec 9, 2021 · 2 comments
Closed
2 tasks done

"can't detect preamble" error with React plugin #153

mdesantis opened this issue Dec 9, 2021 · 2 comments
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified

Comments

@mdesantis
Copy link
Contributor

  • I have tried upgrading by running bundle update vite_ruby.
  • I have read the troubleshooting section before opening an issue.

Description 📖

Hello! I'm playing with Vite Rails, trying to create a Vite Rails + React demo app. The problem is that I'm getting the following error:

Uncaught Error: @vitejs/plugin-react can't detect preamble. Something is wrong. See https://github.com/vitejs/vite-plugin-react/pull/11#discussion_r430879201

The error is reported in the readme of VIte Rails plugin, suggesting that:

In middleware mode, you should make sure your entry index.html file is transformed by Vite

But frankly I know nothing about Vite so my debugging stopped here :D

Reproduction 🐞

  1. Clone the folowing repository: https://github.com/mdesantis/rails-7-demo-vite
  2. bin/setup
  3. foreman start -f Procfile.dev
  4. visit http://localhost:5100/hello_react
Vite Ruby Info

Run bin/rake vite:info and provide the output:

bin/vite present?: true
vite_ruby: 3.0.3
vite_rails: 3.0.1
rails: 7.0.0.rc1
node: v14.17.5
npm: 8.0.0
yarn: 1.22.15
pnpm: 
ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]

installed packages:
rails-7-demo-vite@ /home/maurizio/Sviluppo/rails-7/rails-7-demo-vite
├─┬ vite-plugin-ruby@3.0.4
│ └── vite@2.7.1 deduped
└── vite@2.7.1

Screenshots 📷

Schermata del 2021-12-10 00-09-23

@mdesantis mdesantis added the bug: pending triage Something doesn't seem to be working, but hasn't been verified label Dec 9, 2021
@ElMassimo
Copy link
Owner

ElMassimo commented Dec 9, 2021

As mentioned in the Troubleshooting section, usually when using Vite Ruby the entrypoints are JS files and stylesheets instead of an index.html file, so it's necessary to add the preamble manually when using @vitejs/plugin-react.

To make the integration simpler, Vite Ruby provides a vite_react_refresh_tag to inject the preamble, which you should place in your layout.

@mdesantis
Copy link
Contributor Author

@ElMassimo got it, I didn't notice that section of the guide. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: pending triage Something doesn't seem to be working, but hasn't been verified
Projects
None yet
Development

No branches or pull requests

2 participants