nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
22.64k stars 2.26k forks source link

The Nx CLI could not find or load the native binary for your supported platform (linux-x64). #26831

Open daniorca opened 4 days ago

daniorca commented 4 days ago

Current Behavior

I just migrated using nx migrate from 16.1.0 to 19.4.0

I am running my application in a docker environment.

Now I get the following error when I try to run it : The Nx CLI could not find or load the native binary for your supported platform (linux-x64).

I have tried all possible things including the one mentioned in NX documentation https://nx.dev/troubleshooting/troubleshoot-nx-install-issues without luck> I also verified that in my docker images the @nx/nx-linux-x64-musl and @nx/nx-linux-x64-gnu are present inside the packages, so I am not sure why the NX cli can't find it.

Expected Behavior

The application should run as before with the current platform declared in my dockerfile.

GitHub Repo

No response

Steps to Reproduce

1.

Nx Report

Node   : 22.4.0
OS     : darwin-x64
npm    : 10.8.1

nx (global)        : 19.4.0
nx                 : 19.4.0
@nx/js             : 19.4.0
@nx/jest           : 19.4.0
@nx/linter         : 19.4.0
@nx/eslint         : 19.4.0
@nx/workspace      : 19.4.0
@nx/devkit         : 19.4.0
@nx/eslint-plugin  : 19.4.0
@nx/nest           : 19.4.0
@nx/node           : 19.4.0
@nrwl/tao          : 19.4.0
@nx/webpack        : 19.4.0
typescript         : 5.4.3
---------------------------------------
Community plugins:
@compodoc/compodoc      : 1.1.25
apollo-angular          : 7.0.2
ngx-extended-pdf-viewer : 20.5.0-alpha.1

Failure Logs

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/troubleshooting/troubleshoot-nx-install-issues

Package Manager Version

npm : 10.8.1

Operating System

Additional Information

this is one of my dockerfiles

FROM node:18-alpine As development

WORKDIR /usr/src/app

COPY package.json ./ COPY package-lock.json ./ COPY tsconfig.base.json tsconfig.base.json COPY apps/backend/core-service apps/backend/core-service COPY libs libs

RUN npm install --include=optional RUN npm exec nx run backend-core-service:build

============================ I have added this to my package.json file

"optionalDependencies": { "@nx/nx-linux-x64-gnu": "19.4.0", "@nx/nx-linux-x64-musl": "19.4.0" }

============================= also this is part of my docker-compose file that runs one of the services

core-service: container_name: backend-core-service build: context: . dockerfile: ./apps/backend/core-service/Dockerfile.x86 target: development command: npx nx serve backend-core-service env_file:

guilhermejcgois commented 3 days ago

Same here installing deps in CI environment. We're using ubuntu-latest image and node 18.20

Run npm ci --legacy-peer-deps
  npm ci --legacy-peer-deps
  shell: /usr/bin/bash -e {0}
npm warn deprecated @storybook/expect@[2](...)8.1.3-5: In Storybook 8, this package functionality has been integrated to a new package called @storybook/test, which uses Vitest APIs for an improved experience. When upgrading to Storybook 8 with 'npx storybook@latest upgrade', you will get prompted and will get an automigration for the new package. Please migrate when you can.
npm error code 1
npm error path /home/runner/work/prj/node_modules/nx
npm error command failed
npm error command sh -c node ./bin/post-install
npm error /home/runner/work/prj/node_modules/nx/src/native/index.js:2[4](...)4
npm error     throw loadError
npm error     ^
npm error
npm error Error: Cannot find module '@nx/nx-linux-x64-gnu'

EDIT: adding '@nx/nx-linux-x64-gnu' as optional dependency, updating lockfile and my workflows commands solved the install issue

daniorca commented 3 days ago

I can also confirm that running the following after successfully build my image got this output

docker run -it core-service /bin/sh

/usr/src/app # find ./node_modules -name "nx*.node"

./node_modules/@nx/nx-linux-x64-gnu/nx.linux-x64-gnu.node
./node_modules/@nx/nx-linux-x64-musl/nx.linux-x64-musl.node

and despite of that when running my containers I got the error

NX Missing Platform Dependency The Nx CLI could not find or load the native binary for your supported platform (linux-x64).

MaxKless commented 1 day ago

Hey! This might be because of the native file cache. Can you try setting NX_NATIVE_FILE_CACHE_DIRECTORY to a folder that is accessible from your docker container via an env var? Probably it's some permission issues. I will work on better surfacing the actual error message.

daniorca commented 17 hours ago

@MaxKless

"Hey! This might be because of the native file cache. Can you try setting NX_NATIVE_FILE_CACHE_DIRECTORY to a folder that is accessible from your docker container via an env var? Probably it's some permission issues. I will work on better surfacing the actual error message."

I have changed my dockerfile this way to include your suggestion

###########################

FROM node:18-alpine As development

WORKDIR /usr/src/app

COPY package.json ./ COPY package-lock.json ./ COPY tsconfig.base.json ./ COPY apps/backend/core-service apps/backend/core-service COPY libs libs

RUN npm install --include=optional

RUN mkdir -p /tmp/nx-native-file-cache ENV NX_NATIVE_FILE_CACHE_DIRECTORY=/tmp/nx-native-file-cache

RUN npm exec nx run backend-core-service:build

#####################

the docker image file was created successfully and I ran this command to verify that native files are there

find ./node_modules -name "nx*.node" ./node_modules/@nx/nx-linux-x64-gnu/nx.linux-x64-gnu.node ./node_modules/@nx/nx-linux-x64-musl/nx.linux-x64-musl.node

when running the container I got the error.

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/troubleshooting/troubleshoot-nx-install-issues

EDIT: Also to verify the access to the tmp folder I ran this

/usr/src/app # echo "Test access" > /tmp/nx-native-file-cache/test.txt /usr/src/app # cat /tmp/nx-native-file-cache/test.txt Test access

MaxKless commented 1 hour ago

Did you also verify that the file is copied to /tmp/nx-native-file-cache?