Skip to content

Resolving Error: Cannot find module '@nx/nx-linux-x64-gnu'

Problem Statement

When building Angular projects using Nx in CI environments like GitHub Actions, you may encounter installation errors blocking your pipeline. The core error typically appears as:

shell
Error: Cannot find module '@nx/nx-linux-x64-gnu'
NX   Missing Platform Dependency
The Nx CLI could not find or load the native binary for your supported platform (linux-x64).

This happens because:

  • Nx downloads platform-specific binaries (@nx/nx-linux-x64-gnu) as optional dependencies
  • In CI environments, npm automatically skips optional dependencies (--omit=optional)
  • The missing binary prevents Nx from executing in your pipeline

Solution 1: Install Optional Dependencies Explicitly (Preferred)

  1. Add platform-specific dependencies (npm i -D) to your package.json:
json
{
  // ... existing dependencies ...
  "devDependencies": {
    "@nx/nx-linux-x64-gnu": "^18.0.4",
    // Include additional platforms as needed:
    "@nx/nx-darwin-arm64": "^18.0.4",
    "@nx/nx-darwin-x64": "^18.0.4",
    "@nx/nx-win32-x64-msvc": "^18.0.4"
  }
}

TIP

Use the same version as your main Nx package. Replace 18.0.4 with your actual Nx CLI version.

  1. Update CI scripts to install optional dependencies:
yaml
- name: Install dependencies
  run: npm ci --include=optional  # For 'npm ci'
  # or: npm install --include=optional # For 'npm install'

Solution 2: Clean Install & Rebuild Dependencies

If solution 1 doesn't resolve the issue:

shell
# Clean existing artifacts
npm cache clean --force
rm -rf node_modules package-lock.json

# Full reinstall
npm install --include=optional

WARNING

This approach regenerates package-lock.json. Review lockfile changes in version control afterward.

CI Configuration Examples

GitHub Actions Workflow

yaml
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Install dependencies
        run: |
          npm ci --include=optional

Dockerfile Implementation

dockerfile
FROM node:20-alpine

WORKDIR /app
COPY package*.json .
RUN npm ci --include=optional  # Ensure optional deps are installed

COPY . .
RUN npm run build

Why These Solutions Work

  1. Explicit Dependency Declaration
    Adding @nx/nx-linux-x64-gnu as a dev dependency guarantees npm always downloads the platform-specific binary.

  2. Including Optional Dependencies
    The --include=optional flag overrides npm's default CI behavior that skips these crucial packages.

  3. Cache Cleaning
    Forces npm to refetch package metadata, resolving cases where outdated cache references incorrect package versions.

Additional Considerations

  • npm Version Compatibility: --include=optional requires npm ≥9
  • Platform Binaries: Ensure declared platforms match your CI environment
  • NX Troubleshooting Guide: For advanced scenarios, consult the official Nx troubleshooting documentation

Common Pitfall

Avoid downgrading npm (a common outdated suggestion). Nx v18+ requires npm ≥9. Explicitly including optional dependencies has been the recommended solution since 2024.

These solutions resolve platform-specific binary installation issues while maintaining deterministic builds in CI environments.