-
Notifications
You must be signed in to change notification settings - Fork 155
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
TypeError: Invalid URL on fresh laravel install #316
Comments
Was just about to create an issue for this, it's because of a security issue that's fixed in Vite; https://github.com/vitejs/vite/blob/v6.0.9/packages/vite/CHANGELOG.md#609-2025-01-20 / vitejs/vite@bd896fb So it looks like the Laravel plugin either passes an incorrect URL to |
Yeah, I downgraded vite as a temp. workaround. Works for now |
Hello, I had the same issue. Adding My config: import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/theme.css', 'resources/js/theme.ts'],
refresh: true,
}),
],
build: {
rollupOptions: {
output: {
manualChunks(id) {
if (id.includes('node_modules')) {
return 'vendor';
}
}
}
}
},
server: {
origin: 'http://localhost:5173',
cors: true
}
}); Sincerely, |
From quick debug it seems that laravel plugin initially configures Vite server origin with Latest working vite version you can downgrade to is 5.4.11, or as @SamBrishes mentions, when you provide server origin in the config with valid URL, it is used instead of placeholder and everything works. |
There's no reason to downgrade to Vite 5, as 5.4.12 includes the same fix I think that would also fail. Downgrading to 6.0.8 also resolves the issue for now. |
yes, downgrading to v6.0.8 works, or just use v6.0.9 and set export default defineConfig({
server: {
origin: 'http://localhost:5173',
cors: true,
} If you use some protected Herd/Valet site, you might use something like: export default defineConfig({
server: {
origin: 'https://your-project.test:5173',
cors: true,
} just choose the URL that showed up as
|
Just add the Server config
|
Downgrading to v6.0.8 dont work to me. I install latest vite version (6.0.9) and add configuration from SamBrishes |
This Worked for me |
I had to add port :5173 to make it work |
@SmpManeth / @SamBrishes / @diractorhm 's solution works. It's still annoying that I have to do this. Also, whats up with the rollup Config? Where can I get more info about rollUp? I think I saw some kind of rollup error when I tried to install InertiaJS without Breeze. |
These settings worked for me:
|
The following has the default cors options listed in the docs https://github.com/expressjs/cors#configuration-options Which will address the Vite docs saying: We recommend setting a specific value rather than true to avoid exposing the source code to untrusted origins.
|
I got exactly the same problem. Compltely new to these tools I used the tip given by envolute & diractorhm. |
the solation i found is downgrading
hop this will be fixed soon |
If you are having CORS issues, I've prepared a fix in the If you need special config, we recommend setting the import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: ['resources/css/app.css', 'resources/js/app.js'],
refresh: true,
}),
],
+
+ server: {
+ cors: {
+ origin: 'https://my-app.test'
+ },
+ },
}); I'm holding off merging the fix as it seems the Vite team are working on a similar fix for Vite core. Hopefully that will move quickly. Alternatively, you can use Sorry for the troubles here folks. |
We have released |
I'm still unable to get some vite features working properly using the following dependency versions: Laravel: 11.39.1 When attempting to load a local font:
This is fixed by applying: server: {
origin: "http://localhost:5173",
cors: true,
}, as suggested above. I recognise that setting If anyone has any advice / fixes, I'd appreciate it. |
@finnjsmith, I've noticed you are using the Because this isn't a first-party supported TLD in the Laravel eco-system, you will need to manually allow that domain in the CORS config. You have two options:
APP_URL=https://example-app.local
/* ... */
export default defineConfig({
plugins: [/* ... */],
server: {
// @see https://vite.dev/config/server-options#server-cors
cors: {
origin: [
'https://example-app.local',
// additional hosts...
],
}
}
}); Would love to know how you get on. |
I've created some documentation to help guide anyone with custom setups, e.g., unique TLDs: laravel/docs#10131 |
@timacdonald thank you for your fast and helpful response. I resorted to using a regex statement for all server: {
cors: {
origin: [
// See default supported domains: https://laravel.com/docs/11.x/vite#cors
// Supports: SCHEME://DOMAIN.local[:PORT]
/^https?:\/\/.*\.local(:\d+)?$/,
],
},
}, This works great (even with multiple domains), issue is completely resolved 🥳🤝 |
Hi excellent work, this upgrade solve the problem while running rpm run dev, but now, if I test : nom run build and then php artisan serve i get the error in vite.config i have |
@spawn81, please make sure to upgrade to the latest version of Vite and the Laravel Vite plugin. I would then remove your custom |
|
Great. Did you also remove your custom CORS configuration? Are you still hitting the issue? |
Yep, I've upgraded the package, removed the fix and everything works out of the box as a charm :) |
So great to hear! |
Vite Plugin Version
1.1
Laravel Version
11.31
Node Version
22.13.0
NPM Version
10.9.2
Operating System
Linux
OS Version
6.1.124-1-MANJARO
Web browser and version
Not applicable
Running in Sail?
No
Description
On a fresh laravel installation, I get the following error:
Steps To Reproduce
Create a fresh laravel project
Run
npm install && npm run build
The text was updated successfully, but these errors were encountered: