70

For my admin panel I extract all the assets including the manifest-json.js to mix.setPublicPath(path.normalize('public/backend/')).

All the files get correctly added to the backend folder, and the manifest-json.js file looks as follows:

{
    // all correct here
    "/js/vendor.js": "/js/vendor.js",
    "/js/app.js": "/js/app.js",
    "/css/app.css": "/css/app.css",
    "/js/manifest.js": "/js/manifest.js"
}

the problem is that when using

{{ mix('backend/css/app.css') }}

in my blade-files, it looks in public/manifest-json.js instead of looking for it in backend/manifest-json.js.

How can I make sure the right manifest-json.js file is used?

Chris
  • 3,311
  • 4
  • 20
  • 34

32 Answers32

79

I had same exception after deployment laravel project to server. It was working perfectly fine on localhost but after lot of research I found a solution. If you encounter this exception on server then you have to bind your public path to public_html

Just go to under the app/Providers, you will find your AppServiceProvider file and inside boot() method make the binding as below.

   $this->app->bind('path.public', function() {
        return base_path().'/../public_html';
    });
Gvep
  • 1,196
  • 2
  • 9
  • 18
  • "/home/tebdir/domains/site.com/LaravelApp/../public_html" It's not seems to be right path – Solivan Apr 17 '18 at 04:55
  • 2
    it depends on your folder structure, if your laravelApp and public_html under same directory it won't work, you should configure it according to your structure. – Gvep Apr 17 '18 at 08:57
  • 5
    Many thanks to you, it's much cleaner solution if comparing with others! I would also suggest using some sort of environment constant (set in `.env` file) for specifying path to public directory system-wide. – vintprox Apr 12 '19 at 06:44
  • 1
    Thanks! On my case I have diferent public routes on dev and production. So I have this line before the app->bind call : if (App::environment('production')){ /* */ } – gtamborero Sep 25 '20 at 08:26
  • 1
    This is the answer that works universally - especially if you're on a shared environment. Ensure you've also followed these instructions: https://stackoverflow.com/questions/44868393/laravel-shared-hosting-routes-not-working-properly/46409411#46409411 – andromeda May 21 '21 at 18:15
  • This is the answer that works in my cpanel web hosting thank you – saber tabatabaee yazdi Dec 23 '21 at 19:19
  • this answer is almost good. you don't want to point it to just `/../public_html` arbitrarily. you want to do something like `die(base_path());` and then find out what relative path to point to from the output to where your actual public path (document root) is located, as it's probably outside of the usual laravel directory and somewhere else on a shared hosting – user151496 Jul 12 '23 at 22:40
67

i solved my problem running this command

npm install

and then

npm run production

Thank You.

29

The problem I faced was that the mix()-helper function by default looks for the manifest-json file in /public/manifest-json.js so if you store that file on any other directory level then it will throw that error.

Let's say the manifest-json file is stored in public/app/manifest-json.js, then for a file located in public/app/css/app.css you would use:

<link rel="stylesheet" href="{{ mix('css/app.css', 'app') }}">

The mix()-helper function allows for a second argument, the directory of the manifest file. Just specify it there and it will use the correct manifest file.

Chris
  • 3,311
  • 4
  • 20
  • 34
18

i have same problem as questioner: manifest does not exist for solving it what i have done is ran 2 commands as following:

npm install

and then

npm run dev

and the error is solved now. yippi.

Haritsinh Gohil
  • 5,818
  • 48
  • 50
  • I have already install node js. Use this command for check it node -v npm -v . This working. When command under laravel project npm install . Show this error 'npm' is not recognized as internal or external command in laravel – Bhavik Kalal Jan 25 '21 at 16:41
  • @BhavikKalal have you added the path variable for node js in Environment variables? if not add it and then reopen the command prompt and then check again. – Haritsinh Gohil Jan 27 '21 at 05:27
12

I had the same issue with a Laravel package, its assets were not published:

This solved the issue for me:

php artisan vendor:publish --tag=telescope-assets --force

Sources: https://github.com/laravel/telescope/issues/136 https://github.com/laravel/telescope/issues/250

Denes Papp
  • 3,835
  • 3
  • 32
  • 33
11

In shared hosts and laravel 5.6 tested: after doing standard levels such as explained here; two levels needed: in app/Providers/AppServiceProvider.php:

$this->app->bind('path.public', function() {
    return realpath(base_path().'/../public_html');
});

and in public_html file make .htaccess file with content:

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
  ErrorDocument 404 /index.php
</IfModule>

source: here this file most change for some situations.

that's all and solved my problem

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105
Solivan
  • 695
  • 1
  • 8
  • 16
8

There are 3 ways to solve it, I summarize what the colleagues said above:

The problem is because, you are using mix() in the views.

<link rel="stylesheet" href="{{  mix('dist/css/app.css')  }}">

solution 1 change it to this.

<link rel="stylesheet" href="{{  asset('dist/css/app.css')  }}">

solution 2 If you don't have root access:

Modify the App\Providers\AppServiceProvider file and add the following to the boot() method.

$this->app->bind('path.public', function() {
   return base_path().'/../public_html';
});

solution 3

if you have root access run:

npm install & npm run dev
fafaaf
  • 129
  • 1
  • 2
5

try the following commands:

npm install

npm run dev

Madan Poudel
  • 61
  • 1
  • 4
3

You should run this commands to install npm dependencies and make your frontend files:

$ npm install
$ npm run dev //or production

Now you're done and you can run your laravel project:

$ php artisan serve
2

I have same exception after deployment laravel project to (shared) server when trying to reach the login and register page. It works fine on local machine.

I kept the file and folder structure the same as on my local environment (all files that our in the public folder locally are in the public_html folder on the server).

The solution mentioned above seems to work. Adapted to my file and folder structure I added the following code to AppServiceProvider file and inside boot() method.

$this->app->bind('path.public', function() {
return realpath(base_path().'/public_html');

});

The only issue now is that the CSS of the login, register and dashboard page is messed up. I'm totally new to Livewire, I have no clue how to fix that.

  • Thanks, solved my problem! The css got fixed by removing mix from the css links in the app.blade.php and guest.blad.php – B.Muziekhuis Jan 08 '21 at 08:44
1

In a shared hosting environment, Remove the mix e.g. {!! script(mix('js/manifest.js')) !!}

should be changed to

{!! script('js/manifest.js') !!}

This actually works for me

1

I got the same error

because when I run

npm install
npm run dev

I got some error.

It was fixed when I updated my nodejs version.

Suhendra
  • 91
  • 1
  • 3
1

I'm just posting maybe someone would need it. For me it's worked when I changed in my blade file css and js pointed path. As bellow:

In my blade was this:

<link rel="stylesheet" href="{{ mix('dist/css/app.css') }}">

I changed the MIX to ASSET as:

<link rel="stylesheet" href="{{ asset('dist/css/app.css') }}">

Also the same on JS file to:

<script src="{{ asset('dist/js/app.js') }}"></script>
Jose Pinto
  • 93
  • 1
  • 10
1

If it's the same thing for everybody, in my case laravel-mix seems to be not installed so without changing any files I just installed laravel-mix by running:

npm install laravel-mix@latest --save-dev

AdibMed
  • 59
  • 1
  • 4
1

For bind your public path to public_html, in file index.php add this 3 lines:

$app->bind('path.public', function() {
   return __DIR__;
});

This is work for me on shared hosting

1

If you are having this issue with Laravel Nova or telescope then perhaps you are really missing mix-manifest file. You should have that file inside public/vendor/toolname/ Where toolname can be Nova or Telescope. If you have that folder, you should go ahead and put in your server otherwise you will first have to publish the assets & then put it on server.

MacTavish
  • 59
  • 8
1

Try to Add your public route to your app/Providers/AppServiceProvider.php

public function register()
{
    $this->app->bind('path.public',function(){

    return'/home/hosting-name-folder/public_html'; 
        
    });
}
Gnomo Ario
  • 111
  • 1
  • 3
1
  • Directory Structure like this

    --- public 
       --- app
           --css
              --app.css
           --js
              --app.js
    
  • Import css js in laravel blade file like this

    <link rel="stylesheet" href="{{ asset('app/css/app.css') }}">
    
    <script src="{{ asset('app/js/app.js') }}" type="text/javascript"></script>
    
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
1

step1 npm install npm run production

step 2 refresh by simply closing and opening the project

step 3 replace <link rel="stylesheet" href="{{ mix('css/app.css') }}">

with

<link rel="stylesheet" href="/css/app.css/">

Here you go!!!!!

  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 01 '22 at 05:47
1

I got the same problem when hosting on cpanel

just change from

{{ mix('backend/css/app.css') }}

Becomes

{{ asset('backend/css/app.css') }}

it's solve my problem. don't forget to upvote if this answer help u

GigaTera
  • 782
  • 8
  • 9
0

I change resources/layouts/guest.blade.php and resources/layouts/app.blade.php

    <!-- Styles -->
    <link rel="stylesheet" href="{{asset('css')}}/app.css">

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

and resources/css and resources/js copy my public folder

0

The Mix manifest does not exist.

You can solve this problem by updating the node version.

actually when you run command npm run dev, show the error message "Error: You are using an unsupported version of Node. Please update to at least Node v12.14" so easily you can fix it by updating the node js version

Thanks

0

if your previous setup is correct.but you are looking this type of error it shows The Mix manifest does not exist. then write these command .

npm ci
npm run dev
0

I resolved my problem by this command : npm install npm run dev

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community May 02 '22 at 04:25
  • This does not provide an answer to the question. Once you have sufficient [reputation](https://stackoverflow.com/help/whats-reputation) you will be able to [comment on any post](https://stackoverflow.com/help/privileges/comment); instead, [provide answers that don't require clarification from the asker](https://meta.stackexchange.com/questions/214173/why-do-i-need-50-reputation-to-comment-what-can-i-do-instead). - [From Review](/review/late-answers/31656116) – Alessandro May 06 '22 at 13:57
0

Worked for me on a fresh install of Laravel 9 with Jetstream(using Laradock).

npm run install && npm run development

When running npm run dev the mix was not compiling the files and creating the mix-manifest.json

Rubens
  • 123
  • 1
  • 5
0

There are a lot of answers to these questions, I am posting this question just in case if any miss these points.

Method: 1

Make sure to check the .gitignore file. sometimes it's listed there and doesn't make the file be pushed to git repo

Method: 2

Add this code in webpack.mix.js so you will exactly know where it's placing the mix-manifist.json file

 mix.webpackConfig({
output: {
    path: __dirname + "/public"
  }
});
Ali Hyder
  • 41
  • 12
0

If your hosting does not have npm/node js installed, you can still deploy your Laravel application by following these steps:

Run the 'npm run prod' command on your local PC/project to build the assets for production.

Compress the Laravel project directory (including the node_modules folder) into a zip file.

Upload the zip file to your server and extract it in the desired directory. Make sure the index.php file points to the correct directory.

Configure the .env file to reflect the correct APP_URL.

Finally, create or modify the .htaccess file in the root directory with the following code:

RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] This will redirect all requests to the public directory of your Laravel application.

If your hosting already has npm/node js installed, you can deploy your Laravel application by following these steps:

Upload your project to the server, preferably as a compressed zip file (make sure to exclude the /node_modules folder).

Open the terminal and navigate to the root directory of your project.

Run the 'npm run prod' command to build the assets for production.

Make sure the public/index.php file points to the correct directory.

Configure the .env file to reflect the correct APP_URL.

Finally, create or modify the .htaccess file in the root directory with the following code:

RewriteEngine On RewriteRule ^(.*)$ public/$1 [L] This will redirect all requests to the public directory of your Laravel application.

it always works for me, without change any source code

0

This happened to me because laravel has changed to vite.

I has used this,

<script src="{{ mix('js/app.js') }}"></script>

But the correct command was

@vite('resources/js/app.js')
vimuth
  • 5,064
  • 33
  • 79
  • 116
-1

I had the issue on a shared host, where I was not able to run npm commands. Then I used the simplest way. In the /vendor/laravel/.../Foundation/Mix.php replace

i$manifests[$manifestPath] = json_decode(file_get_contents($manifestPath), true);   

to

$manifests[$manifestPath] = json_decode(file_get_contents('https://your-domain.com/mix-manifest.json'), true);

Not recommended, but it works. You can use it as your last try.

Aagiidu
  • 57
  • 2
  • 6
-1

Faced the same problem on both Windows and Ubuntu. Solved it on Ubuntu (and I presume the solution is simillar in Windows). The problem was due to the fact that my installed npm version was too old.

The solution for me was the following. I installed nvm (NodeVersionManager -version 0.39.1) which allowed me to switch to the latest stable version of node (v16.14.0) and then install npm 8.5.0.

Detailed steps: Linux bash terminal commands:

  1. touch ~/.bash_profile ~/.bashrc ~/.zshrc ~/.profile
  2. sudo apt install curl
  3. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
  4. logout and login Ubuntu user
  5. nvm --version
  6. nvm ls-remote
  7. nvm install 16.14.0
  8. node --version

...then inside the laravel project:

  1. npm ci
  2. npm install -g npm@8.5.0
  3. npm audit fix
  4. npm run dev
Adrian Gh.
  • 59
  • 1
  • 2
-1

Try out this one!!

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

It works for me

Misbakh Ahmed
  • 119
  • 1
  • 6
-2

I found new solution

The problem is mix manifest right? So just redirect to the mix manifest feature. for example, you have:

{{ style(mix('css/backend.css')) }}

just change your code into

{{ style('css/backend.css') }}

it works for me

Pradip Tilala
  • 1,715
  • 16
  • 24