-
Notifications
You must be signed in to change notification settings - Fork 108
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
Dev server serves untransformed raw svelte component instead of extracted CSS #171
Comments
Maybe this is an issue with vite-plugin-svelte and not vite_ruby |
Hi Stefan @buhrmi, please provide a minimal repo (preferably using pnpm) with clear steps on how to reproduce the issue (expected vs actual behavior). |
Hey Maximo, thanks so much for looking into this. Here is a minimal Rails repo: https://github.com/buhrmi/vite_ruby_171 Below are the steps I took to arrive that repo Steps to arrive at that exact repo1. Generate new minimal vite/svelte rails app:
2. Update
|
@StefSchenkelaars Thanks for providing the repo. The problem seems to be related with Vite's I've opened a pull request that fixes this issue by ensuring In the meantime, a workaround you could use is the following: import { defineConfig } from 'vite'
import RubyPlugin from 'vite-plugin-ruby'
import { svelte } from '@sveltejs/vite-plugin-svelte'
export default defineConfig({
plugins: [
RubyPlugin().map(plugin => ({ enforce: 'pre', ...plugin })),
svelte(),
],
}) The order is important: |
bundle update vite_ruby
.Description 📖
When the dev server is running, whenever I try to import a component that has a style tag, the browser tries to load the virtual CSS from the server, but the server responds with the "raw" svelte component file instead of only the extracted CSS, resulting in the error:
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
This does NOT happen if the dev server is not running.
Reproduction 🐞
It's easy to reproduce by following these steps:
https://dev.to/buhrmi/setting-up-a-new-rails-7-app-with-vite-inertia-and-svelte-c9e
Then remove
emitCss: prod
from the vite config. I've added it to the blog post because it circumvents the error for now.Then create a component, eg.
frontend/pages/welcome.svelte
and a route in routes.rb:inertia 'welcome' => 'welcome'
Starting the dev server and visiting https://localhost:3000/welcome will yield the screenshotted error.
Vite Ruby Info
bin/vite present?: true vite_ruby: 3.0.7 vite_rails: 3.0.3 rails: 7.0.0 node: v16.11.0 npm: 8.0.0 yarn: 1.22.15 pnpm: ruby: ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]installed packages:
app@ /home/buhrmi/app
├─┬ @sveltejs/vite-plugin-svelte@1.0.0-next.33
│ └── vite@2.7.10 deduped
├─┬ vite-plugin-ruby@3.0.5
│ └── vite@2.7.10 deduped
└── vite@2.7.10
Screenshots 📷
The text was updated successfully, but these errors were encountered: