Inlogic's avatar

Laravel vite and inertiajs

i made a fresh laravel installation with breeze & vue preset without modifying anything after running npm run dev in which the application was working fine i quit it then do npm run build but the app went blank screen with error from the console

please how do i reolve this issue

the errors from the console below

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:5173/@vite/client. (Reason: CORS request did not succeed). Status code: (null).

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://127.0.0.1:5173/resources/js/app.js. (Reason: CORS request did not succeed). Status code: (null).

my composer.json

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "require": {
        "php": "^8.0.2",
        "guzzlehttp/guzzle": "^7.2",
        "inertiajs/inertia-laravel": "^0.5.4",
        "laravel/framework": "^9.19",
        "laravel/sanctum": "^2.8",
        "laravel/tinker": "^2.7",
        "tightenco/ziggy": "^1.0"
    },
    "require-dev": {
        "fakerphp/faker": "^1.9.1",
        "laravel/breeze": "^1.11",
        "laravel/pint": "^1.0",
        "laravel/sail": "^1.0.1",
        "mockery/mockery": "^1.4.4",
        "nunomaduro/collision": "^6.1",
        "phpunit/phpunit": "^9.5.10",
        "spatie/laravel-ignition": "^1.0"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}
0 likes
14 replies
Sinnbeck's avatar

I assume you mean the other way around, as the error it is showing is from npm run dev ?

What url are you running the app on? Are you using valet or similar?

Inlogic's avatar

@Sinnbeck no when I run npm run dev it's working fine but when i quit npm run dev terminal then run the build after running the build and generating the assets I load the page it's went blank an the console error is what I posted above

Am not using valet am using the php artisan serve command

Sinnbeck's avatar

@Inlogic It should not have this url anywhere in your source code once you stop npm run dev.

http://127.0.0.1:5173/@vite/client

Do you have a file inside of /public named hot? If you do, delete it

2 likes
Inlogic's avatar

@Sinnbeck are you saying when I stop npm run dev I should delete the hot file in the public folder before running the build

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Inlogic It should be deleted automatically. It is created to tell laravel that the dev server is running. Once you stop the dev server, it should be deleted. If it isnt deleted automatically, you should delete it manually.

Inlogic's avatar

@Sinnbeck I have tried it works but other compiled css are now having the same issue including fonts like boostrap-icons css and font files are now show CORS error in the console

ChimaLara4's avatar

@Inlogic please i had same issues currently and i have deleted the hot file in the public and my website homepage is loading , but when click on any link or button to any page , it throws error, please can you help me from here

ChimaLara4's avatar

@Sinnbeck @ please sir i had same issues currently and i have deleted the hot file in the public and my website homepage is loading , but when click on any link or button to any page , it throws error, please can you help me from here

the error is ops look like a page is lost, This is not a fault, just an accident that was not intentional. 404 Not Found.

Please or to participate in this conversation.