Skip to content

fix: CI failing on @rollup/rollup-linux-x64-gnu missing optional dep#1

Merged
QilongTang merged 4 commits intomasterfrom
copilot/fix-github-actions-workflow
Apr 29, 2026
Merged

fix: CI failing on @rollup/rollup-linux-x64-gnu missing optional dep#1
QilongTang merged 4 commits intomasterfrom
copilot/fix-github-actions-workflow

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 29, 2026

npm ci silently skips platform-specific optional dependencies when the lock file was generated on a different OS (npm/cli#4828), causing Vitest/Rollup to throw Cannot find module @rollup/rollup-linux-x64-gnu at startup. Failing run: #25089724982.

Root Cause

package-lock.json was committed from macOS and only recorded @rollup/rollup-darwin-arm64. Since npm ci strictly follows the lock file, @rollup/rollup-linux-x64-gnu was never installed on the Linux CI runner — even a node_modules wipe-and-reinstall fallback failed because it also ran npm ci against the same stale lock file.

Changes

  • Regenerate package-lock.json — primary fix. Deleted the stale macOS-generated lock file and regenerated it from scratch on Linux (npm cache clean --force + npm install). The new lock file records all platform-specific rollup binaries (linux, darwin, win32, etc.) as optional: true, so npm ci on any platform installs the correct native binary.

  • Remove cache: npm from actions/setup-node in both ci.yml and deploy.yml — belt-and-suspenders fix. Prevents a warm npm cache from poisoning optional-dep resolution.

  • Add defensive post-install guard in both workflows — probes the native binary after npm ci; if still absent, wipes node_modules and reinstalls from scratch before tests run. Emits a workflow warning so the fallback is visible in logs.

- name: Verify Rollup native module (clean reinstall if missing)
  run: |
    node -e "require('@rollup/rollup-linux-x64-gnu')" 2>/dev/null || \
      (echo "::warning::@rollup/rollup-linux-x64-gnu missing – performing clean reinstall" && \
       rm -rf node_modules && npm ci)
Original prompt

Create a pull request in DynamoDS/DynoDashGame to fix the GitHub Actions workflow failing in CI.

Context:

  • Workflow: .github/workflows/deploy.yml
  • Failing run: https://github.com/DynamoDS/DynoDashGame/actions/runs/25089724982
  • Failure message (from job logs): Error: Cannot find module @rollup/rollup-linux-x64-gnu during npm test (Vitest startup / Rollup native module).
  • The workflow currently uses actions/setup-node@v4 with node-version: 20 and cache: npm, then runs npm ci, npm test, npm run build, and uploads dist.

Goal:

  • Update the workflow YAML to avoid this intermittent missing Rollup optional dependency issue.

Requirements:

  1. Implement a reliable fix:
    • Prefer removing or adjusting actions/setup-node npm caching if it is the likely root cause.
    • Alternatively/additionally add a small defensive step after install to verify that @rollup/rollup-linux-x64-gnu can be required; if missing, perform a clean reinstall (e.g., remove node_modules and rerun npm ci, avoiding deleting package-lock.json unless necessary).
  2. Keep the workflow behavior the same: tests then build then upload Pages artifact from dist.
  3. Keep changes minimal and well-commented so future maintainers understand why.
  4. Ensure the YAML remains valid and uses pinned major versions for actions.

Deliverables:

  • A PR that updates .github/workflows/deploy.yml accordingly.
  • PR title should mention fixing CI Rollup optional dependency install failure.
  • PR description should:
    • Link to the failing run
    • Explain why the failure occurs
    • Explain the chosen mitigation and tradeoffs (cache vs reliability)

The following is the prior conversation context from the user's chat exploration (may be truncated):

User: Why did this job fail?

Assistant: The job failed during the test step when vitest run tried to start up, because Rollup’s Linux native binary package wasn’t present in node_modules.

From the job log (run 25089724982, job 73513077056):

  • > vitest run
  • Startup Error: Error: Cannot find module @rollup/rollup-linux-x64-gnu
  • The stack points at: node_modules/rollup/dist/native.js
  • Then the step exits with code 1.

This is a known npm/optional-dependencies issue (the log even references https://github.com/npm/cli/issues/4828): the platform-specific optional dependency for Rollup sometimes doesn’t get installed correctly in CI, so Vitest/Vite/Rollup can’t load the native module and aborts.

Link to the failing job log (same ref as the run):
https://github.com/DynamoDS/DynoDashGame/actions/runs/25089724982/job/73513077056#step:5:42

If you want, paste your .github/workflows/deploy.yml install steps (npm ci vs npm i, caching, Node version), and I can suggest the most reliable fix for this workflow.

User: ```
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

  - uses: actions/setup-node@v4
    with:
      node-version: 20
      cache: npm

  - name: Install dependencies
    run: npm ci

  - name: Run tests
    run: npm test

  - name: Build
    run: npm run build

  - uses: actions/upload-pages-artifact@v3
    with:
      path: dist

Assistant: That failure is consistent with an **npm optional-dependency install/cache problem** in Actions:

- `rollup` loads a platform-specific optional package at runtime (on `ubuntu-latest` that’s `@rollup/rollup-linux-x64-gnu`).
- With `actions/setup-node cache: npm`, the cached `~/.npm` content can sometimes produce an install where that optional dependency is **missing**, even though `npm ci` succeeds.
- Then `npm test` → `vitest` → `rollup/dist/native.js` throws: *Cannot find module @rollup/rollup-linux-x64-gnu*.

### Most reliable fix (recommended): don’t use the built-in npm cache here
Remove `cache: npm` from `setup-node` (or switch to a different caching strategy). This avoids restoring a “bad” npm cache state that leads to missing optional deps.

```yaml
- uses: actions/setup-node@v4
  with:
    node-version: 20
    # cache: npm   # remove this

If you want to keep caching anyway

Add a defensive reinstall specifically when the Rollup native module is missing (keeps the workflow resilient):

- name: Install dependencies
  run: npm ci

- name: Ensure rollup native deps present
  run: node -e "require('@rollup/rollup-linux-x64-gnu')" || (rm -rf node_modules package-lock.json && npm i)

(You could also replace npm i with npm ci after regenerating the lock, but typically you don’t want to delete the lock in CI unless you accept lockfile changes.)

Also check: are you on npm 10.x?

Node 20 on GitHub-hosted runners typically uses npm 10+, and this class of issue tends to show up there. If you want an additional mitigation, you can pin npm to a known-good version in the workflow:

- run: npm i -g npm@9

Quick recommendation

Start with the simplest: remove cache: npm, re-run the...

This pull request was created from Copilot chat.

- Remove `cache: npm` from actions/setup-node (primary fix — stale npm
  cache can cause platform-specific optional deps like
  @rollup/rollup-linux-x64-gnu to be skipped, per npm/cli#4828)
- Add defensive verification step after npm ci: if the Rollup Linux
  native binary is still missing, wipe node_modules and reinstall from
  scratch, emitting a workflow warning

Fixes: https://github.com/DynamoDS/DynoDashGame/actions/runs/25089724982

Agent-Logs-Url: https://github.com/DynamoDS/DynoDashGame/sessions/dbdb61eb-cb25-4573-8708-a764c86078ad

Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix GitHub Actions workflow failing in CI fix: CI failing on @rollup/rollup-linux-x64-gnu missing optional dep Apr 29, 2026
Copilot AI requested a review from QilongTang April 29, 2026 03:54
@QilongTang QilongTang marked this pull request as ready for review April 29, 2026 03:58
@QilongTang
Copy link
Copy Markdown
Contributor

@copilot The PR check is failing, fix it as part of this same PR

The CI workflow (ci.yml) used by pull_request checks had the same
`cache: npm` / missing @rollup/rollup-linux-x64-gnu issue as deploy.yml.
Apply identical fixes: remove `cache: npm` and add defensive reinstall guard.

Agent-Logs-Url: https://github.com/DynamoDS/DynoDashGame/sessions/ccd45fb5-a1c2-4023-b9bd-907559539f05

Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot The PR check is failing, fix it as part of this same PR

The CI failure was in a separate ci.yml workflow (the PR check) which also had cache: npm and the same Rollup optional-dep issue. Applied the identical fix there in commit 7ba5193: removed cache: npm from actions/setup-node and added the defensive reinstall guard.

@QilongTang
Copy link
Copy Markdown
Contributor

@copilot The CI check is still failing, try again

…aries

Root cause: package-lock.json was committed from macOS (only had
@rollup/rollup-darwin-arm64). npm ci strictly follows the lock file, so
@rollup/rollup-linux-x64-gnu was never installed on CI, causing the
Vitest startup error even after the node_modules wipe-and-reinstall
fallback (which also uses npm ci against the same stale lock file).

Fix: regenerated package-lock.json from scratch on Linux after clearing
the npm cache. The new lock file records all platform-specific rollup
binaries (linux, darwin, win32, etc.) as optional:true, so npm ci on
any platform will correctly install the matching native binary.

Agent-Logs-Url: https://github.com/DynamoDS/DynoDashGame/sessions/53263425-3d0c-4547-90b3-0557b45f1fd9

Co-authored-by: QilongTang <3942418+QilongTang@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 29, 2026

@copilot The CI check is still failing, try again

Found the real root cause: package-lock.json was committed from macOS and only contained @rollup/rollup-darwin-arm64. Since npm ci strictly follows the lock file, it never installed @rollup/rollup-linux-x64-gnu on CI — even the fallback reinstall failed because it also ran npm ci against the same stale lock file.

Fixed in commit b24b700: regenerated package-lock.json from scratch on Linux (with npm cache clean --force + fresh npm install). The new lock file records all platform-specific rollup binaries (linux, darwin, win32, etc.) as optional: true, so npm ci on any platform now installs the correct native binary. Verified locally with rm -rf node_modules && npm ci && npm test — all 109 tests pass.

@QilongTang QilongTang merged commit 196dda9 into master Apr 29, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants