nrwl / nx

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

The Nx CLI could not find or load the native binary for your supported platform (darwin-arm64). #26930

Closed chriscurnow closed 1 month ago

chriscurnow commented 1 month ago

Current Behavior

When I run any nx command (eg nx list) I get the message:

Missing Platform Dependency

The Nx CLI could not find or load the native binary for your supported platform (darwin-arm64). 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

I realise this is a duplicate of #20280 but none of the discussion there seemed to help.

Expected Behavior

The command works

GitHub Repo

No response

Steps to Reproduce

  1. Create new Nx workspace using the command npx create-nx-workspace@latest angular-monorepo --preset=angular-monorepo
  2. Install a new package (eg npm install -S @angular/material)
  3. Try to list the contents of the package with nx list @angular/material

Nx Report

/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/native-bindings.js:244
    throw loadError
    ^

Error: Cannot find module '@nx/nx-darwin-arm64'
Require stack:
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/workspace-context.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/utils/retrieve-workspace-files.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/plugins/loader.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/plugins/index.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/run/executor-utils.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/devkit-internals.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/assert-workspace-validity.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/build-project-graph.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/project-graph.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/file-utils.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/package-manager.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/child-process.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/migrate/command-object.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/nx-commands.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/bin/init-local.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/bin/nx.js
- /Users/chriscurnow/.nvm/versions/node/v20.15.1/lib/node_modules/nx/bin/nx.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1145:15)
    at Function.resolve (node:internal/modules/helpers:190:19)
    at Module._load (/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js:53:36)
    at Module.require (node:internal/modules/cjs/loader:1233:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/native-bindings.js:135:29)
    at Module._compile (node:internal/modules/cjs/loader:1358:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1416:10)
    at Module.load (node:internal/modules/cjs/loader:1208:32)
    at Module._load (node:internal/modules/cjs/loader:1024:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/workspace-context.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/utils/retrieve-workspace-files.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/plugins/loader.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/plugins/index.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/run/executor-utils.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/devkit-internals.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/assert-workspace-validity.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/build-project-graph.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/project-graph.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/project-graph/file-utils.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/package-manager.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/utils/child-process.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/migrate/command-object.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/command-line/nx-commands.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/bin/init-local.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/bin/nx.js',
    '/Users/chriscurnow/.nvm/versions/node/v20.15.1/lib/node_modules/nx/bin/nx.js'
  ]
}

Node.js v20.15.1

Failure Logs

Node.js v20.9.0
/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/native-bindings.js:244
    throw loadError
    ^

Error: Cannot find module '@nx/nx-darwin-arm64'
Require stack:
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/daemon/server/server.js
- /Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/daemon/server/start.js
    at Module._resolveFilename (node:internal/modules/cjs/loader:1055:15)
    at Function.resolve (node:internal/modules/helpers:136:19)
    at Module._load (/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js:53:36)
    at Module.require (node:internal/modules/cjs/loader:1122:19)
    at require (node:internal/modules/helpers:130:18)
    at Object.<anonymous> (/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/native-bindings.js:135:29)
    at Module._compile (node:internal/modules/cjs/loader:1256:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1311:10)
    at Module.load (node:internal/modules/cjs/loader:1098:32)
    at Module._load (node:internal/modules/cjs/loader:945:12) {
  code: 'MODULE_NOT_FOUND',
  requireStack: [
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/native/index.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/daemon/server/server.js',
    '/Users/chriscurnow/Projects/4cast/fourcast/node_modules/nx/src/daemon/server/start.js'
  ]
}

Node.js v20.9.0

Package Manager Version

No response

Operating System

Additional Information

I have been using Nx for about five years now and have never seen this before. I have created new monorepos many times.

This is a brand new installation of Nx. I updated Nx to latest globally. I read the information at https://nx.dev/troubleshooting/troubleshoot-nx-install-issues, but I didn't understand it – when you say 'Running your install command with ...' which install do you mean?

chriscurnow commented 1 month ago

I actually found a very simple fix for this but I'll leave the issue open because what caused it to happen in the first place is still a bug.

I have a few angular monorepos I have created. I looked at them to see if I could find a difference between them and my latest repo.

It turns out that there is a directory missing in my repo.

The missing directory is node_modules/@nx/nx-darwin-arm64 There is a directory there I think should not be there which is node_modules/@nx/nx-darwin-x64.

Anyway copying the missing directory from another repo fixed the problem.

chriscurnow commented 1 month ago

Is anyone going to look at this issue?

MaxKless commented 1 month ago

Hello :) Sorry for the long response time, there are a lot of issues and we don't always find time to respond to every one.

To me it sounds like it might be this bug from npm where optional dependencies are not always installed: https://github.com/npm/cli/issues/4828 Since you can fix it by adding that repo, it sounds even more likely.

Can you try deleting node_modules and reinstalling. In that case, the dependency should be correctly installed. Please let me know if that worked :)

chriscurnow commented 1 month ago

Hi @MaxKless. That was it. Thanks so much for your help. I can see you get a lot of issues and this really wasn't urgent. It just bothered me that a brand new installation should do that. Anyway, all good now.