daveb2's avatar
Level 3

npm build error on live

I'm trying to deploy a site to live. I have the same code and the same build environment on dev and live, with the same package.json contents, yet I can build successfully on development but on live I get an error about laravel-vite-plugin.

Here is my package.json (same for both dev and live):

{
    "private": true,
    "type": "module",
    "scripts": {
        "dev": "vite",
        "build": "vite build"
    },
    "devDependencies": {
        "@tailwindcss/forms": "^0.5.2",
        "@tailwindcss/typography": "^0.5.0",
        "autoprefixer": "^10.4.7",
        "axios": "^1.6.4",
        "laravel-vite-plugin": "^1.0.0",
        "postcss": "^8.4.14",
        "tailwindcss": "^3.1.0",
        "vite": "^5.0.0"
    },
    "dependencies": {
        "@fortawesome/fontawesome-pro": "^6.5.1",
        "@vitejs/plugin-basic-ssl": "^1.1.0",
        "alpinejs": "^3.13.3",
        "alpinejs-requests": "^1.0.3",
        "tailwindcss-opentype": "^1.1.0",
        "tinymce": "^7.0.0",
        "tw-elements": "^1.1.0"
    }
}

When I do npm run build on live I get:

failed to load config from /home/forge/mysite.com/vite.config.js
error during build:
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'laravel-vite-plugin' imported from /home/forge/mysite.com/vite.config.js.timestamp-1717466511162-3d43acf74c0e2.mjs
    at new NodeError (node:internal/errors:405:5)
    at packageResolve (node:internal/modules/esm/resolve:916:9)
    at moduleResolve (node:internal/modules/esm/resolve:973:20)
    at defaultResolve (node:internal/modules/esm/resolve:1193:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:404:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:373:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:250:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:76:39)
    at link (node:internal/modules/esm/module_job:75:36)

Dev and live are linux (Ubuntu 22.04 Jammy). I have tried experimenting with different versions of vite and laravel-vite-plugin, but I still get the same error. Has anyone seen this, or can anyone suggest a fix/workaround?

0 likes
3 replies
daveb2's avatar
Level 3

This is my laravel log file

[2024-06-04 02:21:38] production.ERROR: Vite manifest not found at: /home/forge/mysite.com/public/build/manifest.json (View: /home/forge/mysite.com/resources/views/errors/static.blade.php) (View: /home/forge/mysite.com/resources/views/errors/static.blade.php) {"exception":"[object] (Illuminate\View\ViewException(code: 0): Vite manifest not found at: /home/forge/mysite.com/public/build/manifest.json (View: /home/forge/mysite.com/resources/views/errors/static.blade.php) (View: /home/forge/mysite.com/resources/views/errors/static.blade.php) at /home/forge/mysite.com/vendor/laravel/framework/src/Illuminate/Foundation/Vite.php:728)
[stacktrace]
#0 /home/forge/mysite.com/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(58): Illuminate\View\Engines\CompilerEngine->handleViewException()
#1 /home/forge/mysite.com/vendor/laravel/framework/src/Illuminate/View/Engines/PhpEngine.php(60): Livewire\Mechanisms\ExtendBlade\ExtendedCompilerEngine->handleViewException()
#2 /home/forge/mysite.com/vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php(22): Illuminate\View\Engines\PhpEngine->evaluatePath()
#3 /home/forge/mysite.com/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(72): Livewire\Mechanisms\ExtendBlade\ExtendedCompilerEngine->evaluatePath()

I don't know why it is showing production.ERROR: Vite manifest not found at... - why is it trying to load vite in production? My .env file has:

APP_NAME=Laravel
APP_ENV=production
APP_KEY=base64:<snip>
APP_DEBUG=false
APP_URL="https://mysite.com"
DhPandya's avatar
DhPandya
Best Answer
Level 12

@daveb2 In the production you have to run npm run build to generate static version of your assets. Also make sure that all required files for vite is present in the production too. https://laravel.com/docs/11.x/vite#running-vite

failed to load config from /home/forge/mysite.com/vite.config.js

This message indicates that your live server does not have vite.config.js on your root

[2024-06-04 02:21:38] production.ERROR: Vite manifest not found at:

This is due to not having a production build of the assets

1 like
daveb2's avatar
Level 3

@DhPandya Thanks, this put me on the right path. Eventually I figured out as well that I didn't have the right dependencies in the production section of my package.json file. It seems like I have to have basically all of my dev dependencies in prod on live in order to run npm run build successfully; I'm not sure if that is best practice for deployment, but I think I prefer it to building on development and then pushing all those assets to our git repository (I use Laravel envoy for deployment).

Please or to participate in this conversation.