Javascript – How to fix error 404 with app.js and app.css in Laravel

cssjavascriptlaravellaravel-6twitter-bootstrap

I am using Laravel 6 and Bootstrap 4.

I made a little app and I was trying to change the background color of the body in the CSS file but I noticed that it didn' work.

So I checked in the tools for the developers and I saw that there are two errors about app.js and css/app.css

"Failed to load resource: the server responded with a status of 404 (Not Found)"

I tried adding a "/" before the path of the CSS but I failed.

View:

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name', 'Laravel') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet">

    <!-- Styles -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
    <link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css">


    <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>

</head>
<body style="overflow: hidden; ">
    <div id="app">
        @include('../inc/navbar')
        <main class="py-4">
            @yield('content')
        </main>
        <br>
        <br>
        <br>
        @include('../inc/footer')
    </div>
    </body>
</html>

CSS:

body {
    background-color: lightblue !important;
}

I would like to see the lightblue body but for some reason it doesn't work. Have you some idea?

Best Answer

I was trying to change the background color of the body in the css file but I noticed that it didn't work.

If this is a fresh install of Laravel, you'll want to run npm install. to install all of the front-end assets (css, js etc). If you have never made any changes to the css or js, in a terminal you'll need to run this command: npm run dev or npm run watch. Here is more documentation for Laravel Mix.

You won't want to touch the actual .css file; it will get overwritten whenever the assets compile. Using the commands above will re-compile all of the .scss files into .css.

Hope this helps!