#Testing a Laravel application that uses Inertia with Gitlab CI/CD

1 messages · Page 1 of 1 (latest)

digital gull
#

I have a Laravel + InertiaJS + Vue3 + Vite app.

I'm using Gitlab CI/CD to try and run tests when new code gets deployed to our repository. We have UAT and Prod environments set up outside of Gitlab CI/CD, but when we try and deploy to Gitlab, I get the following error when trying to run "npm run build"

Could not resolve "../../vendor/tightenco/ziggy/dist/vue.m" from "resources/js/app.js"

Here is my deploy .yml:

image: lorisleiva/laravel-docker:latest

variables:
  CI_COMMIT_REF_SLUG: main

stages:
  - build
  - test

composer:
  
  # The job's stage
  stage: build
  script:
    - composer install --no-interaction --prefer-dist --optimize-autoloader
    - cp .env.example .env
    - php artisan key:generate

  artifacts:
    expire_in: 1 month
    paths:
      - vendor/
      - .env

  # cache:
    key: ${CI_COMMIT_REF_SLUG}-composer
    paths:
      - vendor/

npm:

  stage: build

  cache:
    key: ${CI_COMMIT_REF_SLUG}-npm
    paths:
      - node_modules/

  script:
    - npm install
    - npm run build

  artifacts:
    expire_in: 1 month
    paths:
      - node_modules/
      - public/css/
      - public/js/

pest:
  stage: test
  dependencies:
    - composer
  script:
    - php artisan test --colors=never --coverage-text

As far as I can see, the ziggy requirement is included under "require" of my composer.json, so it should be included when I run composer install?

"require": {
        "php": "^8.1",
        "cloudinary-labs/cloudinary-laravel": "^2.0",
        "guzzlehttp/guzzle": "^7.2",
        "inertiajs/inertia-laravel": "^0.6.8",
        "laravel/framework": "^10.0",
        "laravel/sanctum": "^3.2",
        "laravel/tinker": "^2.8",
        ...
        "tightenco/ziggy": "^1.0"
    },

Does anyone know why this would not be found?

fair halo
#

Sounds like you're running those in different containers or something. At least, isolated. As you can see the it's trying to import from the vendor folder, so that seems to suggest the composer packages aren't installed when running npm