nrwl / nx

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

Unable to npm install project dependencies on nx error #26781

Closed vpernjek closed 2 months ago

vpernjek commented 3 months ago

Current Behavior

Trying to npm install dependencies throws error. I tried to clean install nx globally and delete node_modules and package-lock.json locally and adding the --include=optional flag as per troubleshoot guide but it didn't change.

The behaviour started after upgrading from nx 18 to 19. Reinstalled nvm and node version 21.7.3. Clean install nx globally to latest version 19.3.2.

Expected Behavior

To be able to npm install project dependencies

GitHub Repo

No response

Steps to Reproduce

  1. cloning project
  2. npm install

Nx Report

not able to run nx report

Failure Logs

npm ERR! code 1
npm ERR! path /Users/vpernjek/Desktop/dev/omnisafe/node_modules/nx
npm ERR! command failed
npm ERR! command sh -c node ./bin/post-install
npm ERR! /Users/vpernjek/Desktop/dev/omnisafe/node_modules/nx/src/native/native-bindings.js:244
npm ERR!     throw loadError
npm ERR!     ^
npm ERR! 
npm ERR! Error: dlopen(/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node, 0x0001): tried: '/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node' (code signature invalid in <3024199E-150A-31E2-8827-BAE84FBD48CF> '/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node' (errno=85) sliceOffset=0x00000000, codeBlobOffset=0x0057F860, codeBlobSize=0x0000B078), '/System/Volumes/Preboot/Cryptexes/OS/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node' (no such file), '/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node' (code signature invalid in <3024199E-150A-31E2-8827-BAE84FBD48CF> '/private/var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/nx-native-file-cache-36db5b1/19.3.1-nx.darwin-arm64.node' (errno=85) sliceOffset=0x00000000, codeBlobOffset=0x0057F860, codeBlobSize=0x0000B078)
npm ERR!     at Module._extensions..node (node:internal/modules/cjs/loader:1464:18)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:1205:32)
npm ERR!     at Module._load (node:internal/modules/cjs/loader:1021:12)
npm ERR!     at Module._load (/Users/vpernjek/Desktop/dev/omnisafe/node_modules/nx/src/native/index.js:60:27)
npm ERR!     at Module.require (node:internal/modules/cjs/loader:1230:19)
npm ERR!     at require (node:internal/modules/helpers:179:18)
npm ERR!     at Object.<anonymous> (/Users/vpernjek/Desktop/dev/omnisafe/node_modules/nx/src/native/native-bindings.js:135:29)
npm ERR!     at Module._compile (node:internal/modules/cjs/loader:1368:14)
npm ERR!     at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
npm ERR!     at Module.load (node:internal/modules/cjs/loader:1205:32) {
npm ERR!   code: 'ERR_DLOPEN_FAILED'
npm ERR! }
npm ERR! 
npm ERR! Node.js v21.7.3

Package Manager Version

npm v10.5.0

Operating System

Additional Information

MacOS Sonoma 14.1.2 Apple M2 Pro

mhoffman-bain commented 3 months ago

I am seeing a similar error on windows.

npm error path C:\<PROJECT-NAME>\node_modules\nx
npm error command failed
npm error command C:\WINDOWS\system32\cmd.exe /d /s /c node ./bin/post-install
npm error C:\<PROJECT-NAME>\node_modules\nx\src\native\native-bindings.js:244
npm error     throw loadError
npm error     ^
npm error
npm error Error: \\?\C:\Users\<USERNAME>\AppData\Local\Temp\nx-native-file-cache-79bc8ab\19.3.2-nx.win32-x64-msvc.node is not a valid Win32 application.
npm error \\?\C:\Users\<USERNAME>\AppData\Local\Temp\nx-native-file-cache-79bc8ab\19.3.2-nx.win32-x64-msvc.node
npm error     at Module._extensions..node (node:internal/modules/cjs/loader:1465:18)
npm error     at Module.load (node:internal/modules/cjs/loader:1206:32)
npm error     at Module._load (node:internal/modules/cjs/loader:1022:12)
npm error     at Module._load (C:\<PROJECT-NAME>\node_modules\nx\src\native\index.js:60:27)
npm error     at Module.require (node:internal/modules/cjs/loader:1231:19)
npm error     at require (node:internal/modules/helpers:179:18)
npm error     at Object.<anonymous> (C:\<PROJECT-NAME>\node_modules\nx\src\native\native-bindings.js:66:29)
npm error     at Module._compile (node:internal/modules/cjs/loader:1369:14)
npm error     at Module._extensions..js (node:internal/modules/cjs/loader:1427:10)
npm error     at Module.load (node:internal/modules/cjs/loader:1206:32) {
npm error   code: 'ERR_DLOPEN_FAILED'
npm error }
npm error
npm error Node.js v20.12.2
npm error A complete log of this run can be found in: C:\Users\<USERNAME>\AppData\Local\npm-cache\_logs\2024-07-01T15_05_49_081Z-debug-0.log

I recently updated nx from 17 to 19, and updated node from 18 to 20.

mhoffman-bain commented 3 months ago

I have found a solution to this issue, at least for myself on windows.

I tried a bunch of things, including restarting my computer, deleting the node_modules folder, deleting the .nx folder, downgrading back to node 18, but none of that worked.

What did work was to go into the AppData\Local\Temp\ folder and delete the nx-native-file-cache-79bc8ab folder. I initially was not able to delete this folder due to it being in use, despite vs code and all command prompts being closed. In task manager, it looks like there was a node process left running from a previous install that was sitting in the background despite the command prompt having been closed. After terminating this node process, I was able to delete the nx file cache folder. After deleting this folder, I was able to successfully run npm install nx 19.3.2 and node 20.15.0.

vpernjek commented 3 months ago

I am not seeing nx-native-file-cache-36db5b1 folder anywhere on macOS unfortunately..

simmy-reach88 commented 3 months ago

@vpernjek - Did you check in the /var folder? I was facing the same issue and I removed the nx-native-file-cache files from the /var folder in macOs (This is linked to /private/var) (also remove if any package-lock, node_modules, .nx folder if exists) :

so in your case, the path should be

cd /var/folders/4t/pyry0n8510n6prglnzqb9knr0000gn/T/
rm -r nx-native-file-cache-79bc8ab
npm i

This hopefully should work.

MaxKless commented 3 months ago

Thanks everyone for the input :) If anything happens in the future, you can also try redefining the NX_NATIVE_FILE_CACHE_DIRECTORY env variable to point to a different location without permission problems.

bhouston commented 2 months ago

This is also happening to me as well. It is quite annoying.

This is a true bug in nx. It happens constantly in my Github-Actions CI as well.

Screenshot 2024-07-18 at 11 39 31 AM

bhouston commented 2 months ago

@vpernjek could you reopen this?

I can get consistent reproductions of this issue.

bhouston commented 2 months ago

I've got a reproduction here, just check out this repository:

https://github.com/bhouston/nx-install-failure

And the run these two commands over and over again until you get a failure. On my current machine I get a failure about 50% of the time.

# clear previous install 
npm run clean
# do a fresh install
npm install

Remember that I am on a Mac with the latest OS (beta 15, the latest) using node 22.2.0. If you have a different OS or node version, your results may differ.

I find this error is also occurring in Linux VMs that Github Actions uses. Thus I believe it is not related to MacOS beta.

bhouston commented 2 months ago

As you were reopening the bug @MaxKless, I refiled this as a new bug here: https://github.com/nrwl/nx/issues/26987

bhouston commented 2 months ago

I have identified a fix, I upgraded lerna from "8.1.2" to "8.1.6". I do not think that should have made a difference but it did.

github-actions[bot] commented 1 month ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.