Rails 7 ESbuild error when creating github CI/CD

55 Views Asked by At

I have created a very basic CI/CD. This is my first time and I am unexperienced.

Here is a copy of my ci.yml

name: Tests

on:
  pull_request:
    branches:
      - "*"
  push:
    branches:
      - "main"

jobs:
  test:
    runs-on: ubuntu-latest
    services:
      postgres:
        image: postgres:latest
        env:
          POSTGRES_USER: postgres
          POSTGRES_PASSWORD: password
        ports: ["5432:5432"]

    steps:
      - uses: actions/checkout@v4
      - name: Setup Ruby
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Run Tests
        env:
          DATABASE_URL: postgres://postgres:password@localhost:5432/test
          RAILS_ENV: test
        run: |
          bin/rails test:prepare
          bin/rails db:test:prepare
          bin/rails test

This seems to be working just fine, but something in this process is throwing the following error:

Run bin/rails test:prepare
yarn install v1.22.21
[1/4] Resolving packages...
[2/4] Fetching packages...
warning [email protected]: The engine "pnpm" appears to be invalid.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
Done in 9.18s.
yarn run v1.22.21
$ esbuild app/javascript/*.* --bundle --sourcemap --format=esm --outdir=app/assets/builds --public-path=/assets
Error: R] Could not resolve "stimulus-clipboard"

    app/javascript/application.js:8:22:
      8 │ import Clipboard from 'stimulus-clipboard'
        ╵                       ~~~~~~~~~~~~~~~~~~~~

  You can mark the path "stimulus-clipboard" as external to exclude it from the bundle, which will remove this error and leave the unresolved path in the bundle.

Looking into this issue, I need to inform ESbuild of this "stimulus-clipboard". I have tried creating a esbuild.config.js and adding some code to it, but this has not worked for me. I also tried running "rails stimulus:manifest:update", but no success either.

I am trying to resolve this error and use the CI by excluding or properly including the package

1

There are 1 best solutions below

0
christian torelli On

I found the answer to this, "stimulus-clipboard" was not installed properly.

I confirmed this by viewing the yarn.lock file in the project root directory. I searched that file for "clipboard" and found 0 results, confirming it was not there. Using "yarn add stimulus-clipboard" it was properly added and then rebuilt.

This should be a general troubleshooting process for any similar issues in the future