Vite Manifest Not Found: Solutions for Laravel Applications
Problem Statement
When deploying Laravel applications with Vite to production environments (particularly cPanel shared hosting), developers frequently encounter the "Vite manifest not found" error. This error occurs when Laravel cannot locate the manifest.json
file that Vite generates during the build process, typically showing this message:
Vite manifest not found at: /path/to/public/build/manifest.json
Missing Vite Manifest File
Did you forget to run `npm install && npm run dev`?
The issue often arises due to:
- Incorrect file structure in cPanel environments
- Missing build files in production
- Node.js version incompatibility
- Incorrect configuration for non-standard directory layouts
Primary Solutions
1. Build Assets for Production
The most common solution is to ensure you've built your assets for production:
npm install
npm run build
WARNING
The public/build
directory is typically in .gitignore
. You must run npm run build
on your production server or include the built files in your deployment process.
2. Verify Node.js Version Compatibility
Vite requires a modern Node.js version (16+). Check your Node.js version:
node --version
If outdated, upgrade using nvm (Node Version Manager):
nvm install 20
nvm use 20
Or on Ubuntu systems:
sudo npm cache clean -f
sudo npm install -g n
sudo n stable
3. Adjust Configuration for cPanel Directory Structure
cPanel often requires moving public files to public_html
. Update your vite.config.js
:
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
// Add public directory configuration for cPanel
buildDirectory: 'build',
publicDirectory: '../public_html' // Adjust based on your structure
}),
],
});
4. Update Laravel's Public Path (Advanced)
For complex directory structures, modify public/index.php
:
<?php
use Illuminate\Http\Request;
define('LARAVEL_START', microtime(true));
// ... existing code ...
$app = require_once __DIR__.'/../bootstrap/app.php';
// Set custom public path
app()->usePublicPath(__DIR__);
$app->handleRequest(Request::capture());
Alternative Approaches
Use Build Directory Customization
In AppServiceProvider.php
, you can customize the build directory:
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Vite;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
Vite::useBuildDirectory('.');
}
}
Manual Build Folder Management
For cPanel deployments with separated directories:
- Run
npm run build
locally - Upload the generated
build
folder to both locations:- Your application's
public
directory - The
public_html
directory (if using cPanel's standard structure)
- Your application's
TIP
This ensures Laravel finds the manifest regardless of which path it's checking.
File Permission Issues
If the manifest file exists but isn't accessible, check permissions:
sudo chown www-data:www-data -R public/build/
sudo chmod g+w -R public/build/
Complete cPanel Deployment Checklist
- Verify Node.js version (16.0+ recommended)
- Install dependencies:
npm install
- Build assets:
npm run build
- Check directory structure matches your deployment
- Verify file permissions for the build directory
- Update configuration if using non-standard public directory
DANGER
Never run npm run dev
in production. This command starts a development server and is not suitable for production environments. Use npm run build
instead.
Troubleshooting Common Issues
- Build failures: Check console output for specific errors during
npm run build
- Missing dependencies: Ensure all required packages are in your
package.json
- Caching issues: Delete
node_modules
and reinstall if encountering strange behaviors - Path conflicts: Double-check all path configurations in both Laravel and Vite
By following these solutions, you should resolve the "Vite manifest not found" error and successfully deploy your Laravel application with Vite bundling.