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

[1.x] Fix Invalid URL issue with Vite 6.0.9 #317

Merged
merged 3 commits into from
Jan 21, 2025
Merged

Conversation

batinmustu
Copy link
Contributor

This PR resolves the “Invalid URL” error encountered when running npm run dev or npm run build. The issue arises from the requirement introduced in Vite 6.0.9 that server.origin must be a valid URL. The configuration has been updated to comply with this requirement.

error when starting dev server:
TypeError: Invalid URL
    at new URL (node:internal/url:818:25)
    ...

This commit updates the default server.origin value in laravel-vite-plugin from __laravel_vite_placeholder__ to http://laravel-vite-plugin.test. This change resolves the “Invalid URL” error that occurred when attempting to create a URL with the server.origin value following the update to Vite 6.0.9, which enforces server.origin to be a valid URL.

The updated value has been tested in Vite 6.0.8 and earlier versions, confirming compatibility and no issues when used as a valid link.

Vite 6.0.9 changes

This PR resolves the "Invalid URL" error that occurred due to the requirement that the server.origin value be a URL, introduced in the recently released Vite 6.0.9.
@meduzen
Copy link

meduzen commented Jan 20, 2025

It's fixed in Vite 6.0.10.

Backlinks: #316 and vitejs/vite#19241.

@jayan-blutui
Copy link

jayan-blutui commented Jan 20, 2025

While Vite 6.0.10 fixes this issue. I noticed I am getting a CORS issue in development mode.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://laravel.test:5173/@vite/client. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 200.

Update: This error did not occur previously.

@timacdonald timacdonald marked this pull request as draft January 20, 2025 22:05
@timacdonald
Copy link
Member

Converting this to a draft while I investigate the issue further.

@jayan-blutui
Copy link

jayan-blutui commented Jan 21, 2025

I found that adding the following config to the vite.config.js file fixes the CORS issue:

server: {
  cors: true,
},

@timacdonald
Copy link
Member

@jayan-blutui, although that does get things back on track, you should keep in mind that it exposes you to the vulnerability that Vite patched: GHSA-vg6x-rcgg-rjx6

I'm working on a Laravel-flavoured CORS fix: #318

@jayan-blutui
Copy link

Mate, you're a legend! Totally overlooked that vulnerability.

Really appreciate the work you do 💯

@timacdonald
Copy link
Member

Thanks, @batinmustu.

I've pushed a couple of commits to:

  1. Rename the placeholder to http://__laravel_vite_plugin__.test
  2. Ensure we replace the URL while the dev server is running.

@imblusys
Copy link

I found that adding the following config to the vite.config.js file fixes the CORS issue:

server: {
  cors: true,
},

Hi, This is not working for me on localhost, there is another solution? thank you

@taylorotwell taylorotwell merged commit 1501f5c into laravel:1.x Jan 21, 2025
4 checks passed
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 this pull request may close these issues.

6 participants