Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

LaraBABA's avatar

Bug in Laravel 6? Laravel mix version working locally but not in remote

Hello,

I am having a weird issue, when I try to version my app.js and custom.css it works locally(even when compiled in production), but as soon as I upload all the files form the public folder to my public_html in the remote, the versionining of the files do not working.

   "laravel/framework": "6.2",
    "laravel-mix": "^5.0.5",

Here is what I tried:

webpack:

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
   .styles(['resources/css/custom.css'], 'public/css/custom.css');

if (mix.inProduction()) {
    mix.version();
}

Also tried this:

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
   .styles(['resources/css/custom.css'], 'public/css/custom.css');

mix.version();

In my blade files:

I tried:

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

and

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

As I said it is working on my local but not on the production server.

I compile everything locally and upload all to the remote.

Is there a file on the local that is needed on the remote for this to work correctly please?

Thank you.

0 likes
21 replies
LaraBABA's avatar

yes, this is something I run all the time.

The strange thing is that on my local the production version shows the versioning but the production version on my remote server shows the files "as is" with no ?version959807diuh in the file url

jlrdw's avatar

Check for a permission problem where the files are written to, make sure that folder has the correct write permissions.

Snapey's avatar

You should know that versioning produces a manifest file that swaps out the URLs for the compiled assets when you run the mix helper in your blade file

If you compile in one environment then deploy in another there is a good chance that the URLs are wrong

have a look here https://laravel.com/docs/8.x/mix#versioning-and-cache-busting and read down to Custom Mix Base URLs

Before you do that, check the URLs on production using the view Source in the browser and see what URLs are currently being inserted

LaraBABA's avatar

Oh I see, I did not understand the doc in this way when I read this part: "If your Mix compiled assets are deployed to a CDN separate from your application"

I thought they meant "Pulling assets from other domains that the one you are actually on"(and not always based on the local copy of the app). .

Regarding the URLs, do you mean the output in the HTML of the production app? Yes this is the first thing I checked. In fact the app is pulling all the assets correctly but no versioning.

Regarding the manifest, I see this(no prefixed domains):

    "/js/app.js": "/js/app.js?id=6d7f4a719010cc0af4ce",
    "/css/app.css": "/css/app.css?id=467f5aa4dc28a3931388",
    "/css/front-custom.css": "/css/front-custom.css?id=f082a251ca5b085fcc83"

I always upload the manifest on the production server.

Based on the manifest above, and the trick of added this: 'mix_url' => env('MIX_ASSET_URL', null)

I believe the new manifest will then become something like:

    "https://mywebsite.com/js/app.js": "/js/app.js?id=6d7f4a719010cc0af4ce",
    "https://mywebsite.com/css/app.css": "/css/app.css?id=467f5aa4dc28a3931388",
    "https://mywebsite.com/css/front-custom.css": "/css/front-custom.css?id=f082a251ca5b085fcc83"

If this is the case, why would the above manifest works when the app is compiled in production(and run locally) but not remotely?

As I have a .dev local domains and a .com remote domain.

I will try to add "'mix_url' => env('MIX_ASSET_URL', null)" to see if this helps.

Thanks

Snapey's avatar

So you must use the mix command in the blade file if you want the url of the asset swapped out.

make sure you clear the compiled views after uploading

Looking at the manifest,if you consider it being key,value pairs then mix() helper will swap the url found in key for its value. I notice that in your mix command you dont start the asset name with /

perhaps this is causing it to miss the match

LaraBABA's avatar

I tried both:

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

and

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

Ran "npm run production" on my local and uploaded the public files to my public_html on the remote(as usual).

I also added this on the local before compiling the files in app.php:

    'mix_url' => env('MIX_ASSET_URL', null'),

in the .env:

MIX_ASSET_URL=https://myproduction-website.com

On the remote I have ran these commands via SSH:

php artisan cache:clear
php artisan view:clear
php artisan config:clear
php artisan config:cache
php artisan route:cache

The manifest has also been uploaded to the remote.

All cleared.

Looking at the source locally(with the production version), I see this:

<link href="https://website.dev/css/app.css?id=61c5d68bf754e5e9826c" rel="stylesheet">

On the remote I see this:

<link href="https://myproduction-website.com/css/app.css" rel="stylesheet">

I checked the manifest after running:

npm run production

And still see this:

{
    "/js/app.js": "/js/app.js?id=c779354ad6434aa03fe0",
    "/css/app.css": "/css/app.css?id=61c5d68bf754e5e9826c",
    "/css/custom.css": "/css/custom.css?id=cf672432b5b3ad2ffa22"
}

Should "https://myproduction-website.com" be showing there?

LaraBABA's avatar

I did not see your comment here, let me check, good point.

LaraBABA's avatar

I have replaced all the mix() in the blade files to:

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

(added the forward slash).

Ran "npm run production", uploaded the files to the remote, emptied the cache via SSH with the command:

php artisan cache:clear
php artisan view:clear
php artisan config:clear
php artisan config:cache
php artisan route:cache

Same issue, no versioning added to the remote server only on the local production version.

Snapey's avatar

If you rename the manifest file, do you get an exception thrown?

(checks that the manifest is actually found)

Snapey's avatar

Looking at the code, another thought. It reports errors differently if it can't verify the presence of the css or js file. It just logs it. Have you checked the error logfiles?

LaraBABA's avatar

I did what you suggested and renamed the manifest file, no errors. I checked the /laravel/storage/logs , nothing logged there.

I am wondering if this is a bug with this version of Laravel + mix.

LaraBABA's avatar

So today I carried on with it but no chance.

I added this in config/app.php

   'mix_url' => env('MIX_ASSET_URL', 'https://mywebsite.com'),

In the .ENV

MIX_ASSET_URL=https://mywebsite.com

Updated Laravel mix to:

       "laravel-mix": "^5.0.5",

My manifest:

{
    "/js/app.js": "/js/app.js?id=78dc143d65d88ca4af99",
    "/css/app.css": "/css/app.css?id=86a85fef72ef36124112",
    "/css/custom.css": "/css/custom.css?id=cf672432b5b3ad2ffa22"
}

My view paths:

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

I have also tried with:

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

My webpack.mix

mix.js('resources/js/app.js', 'public/js')
    .sass('resources/sass/app.scss', 'public/css')
    .styles(['resources/css/custom.css'], 'public/css/custom.css')
    .version();

Local:

<link href="/css/app.css?id=86a85fef72ef36124112" rel="stylesheet">
<script src="/js/app.js?id=78dc143d65d88ca4af99"></script>

Remote:

<link href="https://mywebsite.com/css/app.css" rel="stylesheet">
<script src="https://mywebsite.com/js/app.js"></script>

I deleted the manifest on the remote, no error, no logs.

What else could I try please? I am so confused....

The manifest CHMOD is rw-rw-r-- 0664

Thank you.

LaraBABA's avatar

No exception, now. I tried more things tonight(detailed above). But still no luck...

Snapey's avatar

at this point, the chance of it being a bug is highly unlikely

vstruhar's avatar
vstruhar
Best Answer
Level 10

In my case I accidentally uploaded public/hot file to production, so the public/mix-manifest.json was ignored when calling mix function in script tag.

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

@LaraBABA please did you find the solution? please help me i'm stuck i can't solve the problem.

LaraBABA's avatar

@amm_dodo Yes, the problem is that when you upload your mix-manifest.json paste it in the public folder of your laravel app(and not in the public_html). This was the bug. I could not get it to work in the public_html, even after changing certain settings in webpack(if I remember correctly).

pilat's avatar

Not sure that I understand how MIX_ASSET_URL works. Say, I decided to serve my assets from another host. So, I reference them with that mix() helper in all my templates and the URLs are OK.

Now, the deployment part: I currently have npm run prod as part of my Deployment script on Laravel Forge. This produces manifest.json with references to versioned files names. If I have another server "just for statics", I'll need to run 'nom run prod' on that server as well. But the question is: will the manifests on both sites match?

Please or to participate in this conversation.