The Mix Manifest Does Not Exist Where You Expect It To
When extracting assets for an admin panel using Laravel Mix, a common scenario involves copying the entire build output to a specific public subdirectory, such as public/backend/. Developers often set the public path in their configuration like this:
mix.setPublicPath(path.normalize('public/backend/'));
This approach works perfectly for static assets. Your JavaScript bundles and stylesheets appear exactly where they need to be in the backend folder, and Blade directives like {{ mix('backend/css/app.css') }} render correctly because Mix is looking at the right physical location to generate the source maps and hashes.
However, a subtle bug frequently surfaces when dealing with the manifest file itself. If you extract the build output via a simple command-line copy or a post-compile script that duplicates the entire public/mix-manifest.json (or its .js variant depending on your version) into the new folder, you end up with two copies of the manifest: one in public/mix-manifest.json and another in public/backend/mix-manifest.json.
The problem arises because Laravel's asset caching mechanism does not automatically switch to the new location just because you changed the public path. When the application boots up or when a Blade template is rendered, Laravel loads the manifest file from the root of your configured public directory by default unless explicitly told otherwise. Consequently, if you have a custom backend folder with its own copy of the manifest, the request handler often defaults to reading public/mix-manifest.json.
This creates a discrepancy where your HTML references point to assets inside the backend/ subdirectory (because that is what your JS and CSS files are actually sitting in), but the manifest cache lookup happens against the root directory. Since the root directory might not contain the specific hashed filenames generated for that specific build run, or if the manifest structure differs slightly due to how it was copied, you get 404 errors or incorrect asset loading.
To resolve this, you must ensure that the mix-manifest.json (or .js) file exists in the same location relative to your public path that Mix is configured to read. If you are using setPublicPath('public/backend/'), the application expects the manifest at backend/mix-manifest.json.
The most robust solution is to prevent Laravel from reading the root manifest and force it to read the one inside your custom backend folder. This can be achieved by adjusting the APP_URL or ensuring your asset caching configuration aligns with the new physical path. Alternatively, if you are managing this via a deployment script, ensure that only the necessary assets, including the manifest, are copied to the target directory and that any previous cache files in the root public folder are cleared.
Another approach involves verifying how Mix generates its manifest. If you are using mix.setPublicPath(), the generated manifest file itself should reflect paths relative to that new public path. If the extracted manifest in the backend folder still contains absolute paths pointing to the root (e.g., /css/app.css instead of /backend/css/app.css), then simply copying the file is insufficient. You may need to regenerate the manifest specifically for the backend build or modify the extraction logic to strip or rewrite the base path within the manifest JSON itself before deployment.
Ultimately, the "manifest does not exist" error in this context is rarely about the file being missing entirely; it is about the path resolution mismatch between where the assets physically live and where Laravel's cache loader expects the manifest definition to be. Aligning these paths by ensuring the manifest resides exactly at public/backend/mix-manifest.json when using a backend public path, or by clearing the cache (php artisan cache:clear) after moving assets, usually restores the correct asset resolution without needing complex path rewriting logic.