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

Laravel vite with unocss devtools not working #2822

Closed
4 tasks done
HassanDomeDenea opened this issue Jun 30, 2023 · 3 comments · Fixed by #3255
Closed
4 tasks done

Laravel vite with unocss devtools not working #2822

HassanDomeDenea opened this issue Jun 30, 2023 · 3 comments · Fixed by #3255

Comments

@HassanDomeDenea
Copy link

UnoCSS version

0.53.4

Describe the bug

I set up fresh laravel, using vite I added unocss to app.ts:

//app.ts

import 'uno.css'
import 'virtual:unocss-devtools'

import {createApp} from 'vue'
import App from './components/App.vue'
createApp(App).mount('#app')

After runing npm run dev, and visiting the website, an error occurred in terminal:

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at IncomingMessage.<anonymous> (file:///D:/laragon/www/hddclinic3/node_modules/@unocss/vite/dist/index.mjs:1059:23)

Also In browser the error was:
Access to fetch at 'http://[::1]:5175/@unocss-devtools-update' from origin 'http://127.0.0.1:8000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

After couple of maniputlations, I added this line to file:

//node_modules/@unocss/vite/dist/client.mjs

function post(data) {
    return fetch("__POST_PATH__", {
++   mode: 'no-cors',
        method: "POST",
        headers: {
            "Content-Type": "application/json"
        },
        body: JSON.stringify(data)
    });
}

And it worked! So I wanted to share this because I searched for it and din't find any official or workaround.

Reproduction

install laravel fresh app.

Follow the documentation in:
https://unocss.dev/integrations/vite#vite-plugin

And adding the feature:
https://unocss.dev/integrations/vite#edit-classes-in-devtools

System Info

node v 18.6.0
php 8.2
laravel x10
vite 4.0
unocss ^0.53.4

Validations

@slavamak
Copy link

slavamak commented Jul 1, 2023

Same issue here

@mortona42
Copy link

I had this issue with a Drupal site and the code change provided above works. I believe I have cors headers set correctly in Drupal, and the error is being triggered by vite not providing the headers.

@mortona42
Copy link

For anyone wondering how to use this:
export default defineConfig({ plugins: [ UnoCSS({ fetchMode: 'no-cors' }), ],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants