Rails 7 ESbuild 创建 github CI/CD 时出现错误

问题描述 投票:0回答:1

我创建了一个非常基本的 CI/CD。这是我第一次,没有经验。

这是我的 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

这似乎工作得很好,但在此过程中出现了以下错误:

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.

考虑到这个问题,我需要通知 ESbuild 这个“刺激剪贴板”。我尝试创建 esbuild.config.js 并向其中添加一些代码,但这对我不起作用。我也尝试运行“railsstimulus:manifest:update”,但也没有成功。

我正在尝试解决此错误并通过排除或正确包含该包来使用 CI

ruby-on-rails ruby continuous-integration github-actions esbuild
1个回答
0
投票

我找到了答案,“stimulus-clipboard”没有正确安装。

我通过查看项目根目录中的yarn.lock文件确认了这一点。我在该文件中搜索“剪贴板”并找到 0 个结果,确认它不存在。 使用“纱线添加刺激剪贴板”,它被正确添加,然后重建。

这应该是未来任何类似问题的一般故障排除过程

© www.soinside.com 2019 - 2024. All rights reserved.