Error: Cannot find module '@nx/nx-linux-x64-gnu'
Asked Answered
S

4

22

I'm trying to run the build of my Angular project using NX in the CI with GitHub Actions, but it fails with errors such as:

npm ERR! code 1
npm ERR! path /runner/_work/myapp/node_modules/nx
npm ERR! command failed npm ERR! command sh -c node ./bin/post-install
npm ERR! /runner/_womyapp/node_modules/nx/src/native/index.js:244
npm ERR!     throw loadError
npm ERR!     ^
npm ERR!
npm ERR! 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 likely means that optional dependencies were not installed correctly, or your system is missing some system dependencies. For more information please see https://nx.dev/recipes/troubleshooting/troubleshoot-nx-install-issues

Error: Process completed with exit code 1.

Saliferous answered 13/2, 2024 at 15:18 Comment(2)
For me the problem seems to have been that I ran npm install locally on my windows machine, fixing package-lock.json to @nx/nx-win32-x64-msvc, so later npm ci on the GitLab Linux agent installed that instead of the required @nx/nx-linux-x64-gnu. Seems that package-lock.json is inherently unportable?Pori
Please format your output using a code block ({} button) instead of a quote block (" button).Alroi
S
23

There are several suggested solutions on GitHub for this issues, for example deleting node_modules and package-lock.json and regenerating them with npm install, however none of such solutions worked for me.

I finally found the solution pointed out by the user k3nsei which worked for me:

  1. Add the following to your package.json file (replace the 18.0.4 nx version with the one you are using, preferably the latest one):
  "optionalDependencies": {
    "@nx/nx-darwin-arm64": "18.0.4",
    "@nx/nx-darwin-x64": "18.0.4",
    "@nx/nx-linux-x64-gnu": "18.0.4",
    "@nx/nx-win32-x64-msvc": "18.0.4"
  },
  1. In your CI scripts, run the npm ci or npm install with --include=optional, example:
- name: Install dependencies
  run: npm ci --include=optional
Saliferous answered 13/2, 2024 at 15:18 Comment(1)
I am having this same issue on Bitbucket, running a node node:18.20.3 image. Only the optional fix seemed to work. I have not experienced this before with an NX PNPM combo, but I tried to move away from pnpm and just have a root npm package file. Works fine now.Jadwigajae
E
2

it is old issue https://github.com/npm/cli/issues/4828

to fix it i did this:

  1. downgrade npm to 6 version (npm install -g npm@6)
  2. removed lock.json
  3. npm install
  4. returned newer version of npm (npm install -g npm@10)
  5. again npm install for updating lock file to newer version

now i have perfect nx (and other libs too) optional deps inside lock.json. and i do not have extra/unwanted optionalDependencies in package.json

Euphemia answered 23/4, 2024 at 11:8 Comment(1)
Steps 2 and 3 were sufficient to make it work for me. No down- and upgrade of npm was necessary.Alroi
P
2

Removing package-lock.json and running "npm install" did the trick for me

Paulenepauletta answered 28/5, 2024 at 20:7 Comment(1)
This works! thank you :)Furring
Y
0

Just in case it helps someone I found that in addition to deleting node_modules and package_lock.json I also had to run 'npm cache clean --force'. This finally cleared the issue up.

Yeargain answered 17/7, 2024 at 23:36 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.