ankush981's avatar

Uncaught ReferenceError: Livewire is not defined

I'm using laravel 8 and im getting error Uncaught ReferenceError: Livewire is not defined

and i don't want to publish livewire assets

0 likes
12 replies
bugsysha's avatar

Which version are you on cause in the docs it says "Include the JavaScript (on every page that will be using Livewire)."

...
    @livewireStyles
</head>
<body>
    ...

    @livewireScripts
</body>
</html>
chaudigv's avatar

Did you ran php artisan livewire:publish --assets to publish frontend assets?

6 likes
ankush981's avatar

its working with artisan serve but when i'm running with out artisan serve command then its not working

1 like
khaledw62's avatar

in Your config/livewire.php change the asset_url to public

/*
    |--------------------------------------------------------------------------
    | Livewire Assets URL
    |--------------------------------------------------------------------------
    |
    | This value sets the path to Livewire JavaScript assets, for cases where
    | your app's domain root is not the correct path. By default, Livewire
    | will load its JavaScript assets from the app's "relative root".
    |
    | Examples: "/assets", "myurl.com/app".
    |
    */

    'asset_url' => 'public',

and that's because livewire published the vendor folder to your public dir

1 like
xeisu's avatar

If you use xampp you should change asset_url to ../ in your config/livewire.php. You get this file by entering this command: php artisan livewire:publish --config

1 like
Snapey's avatar

Such problems ALWAYS stem from hosting the Laravel app in an invalid and (likely) insecure manner

1 like
Blockhunt's avatar

For my case, as my web url is [ ip address/projectName/public/ ] I change the livewire's asset url to '../public'

'asset_url' => '../public',
4 likes

Please or to participate in this conversation.