oliverbj
oliverbj

Reputation: 6052

Laravel deployment with Forge - VIte manifest not found

I am trying to deploy a brand new Laravel 9 site with Vite.

I have the site running locally just fine, and the deployment is running via Laravel forge using the default deployment script:

cd /home/forge/default
git pull origin $FORGE_SITE_BRANCH

$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
fi

Before pushing my changes from my local to remote server, I run:

npm run build

However, when the site has been deployed to forge, I get the below error:

(Exception(code: 0): Vite manifest not found at: /home/forge/default/public/build/manifest.json at /home/forge/default/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php:139)

When I ssh into my server, this is the content of the /public folder:

.
└── public/
    ├── favicon.ico
    ├── index.php
    └── robots.txt

Shouldn't the /build folder be available on the production site as well, or am I missing something? Please note in my standard generated .gitignore file, these paths are excluded:

/public/build
/public/hot
/public/storage

Upvotes: 4

Views: 3736

Answers (1)

oliverbj
oliverbj

Reputation: 6052

EDIT 07-02-2023:

I ended up changing my .gitignore. I removed the below:

/public/build
/public/hot
/public/storage

And added the below:

!/public/build
/public/hot
/public/storage

Which also fixed the issue.

Original answer:

I fixed this by updating the deployment script on Laravel Forge to include npm install and npm run build:

cd /home/forge/default
git pull origin $FORGE_SITE_BRANCH

$FORGE_COMPOSER install --no-interaction --prefer-dist --optimize-autoloader

( flock -w 10 9 || exit 1
    echo 'Restarting FPM...'; sudo -S service $FORGE_PHP_FPM reload ) 9>/tmp/fpmlock

if [ -f artisan ]; then
    $FORGE_PHP artisan migrate --force
fi

npm install
npm run build

I looked at this reply to a similar question, which basically states:

Asset building for production is a known problem that has multiple known solutions:

  1. You build your assets locally and commit them to Git
  2. You let your deployment script (and server) build the assets for you
  3. You build your assets locally, publish them to the cloud, and tell your deployment script to download them

I chose option 2 :)

Upvotes: 13

Related Questions