nx-console: Process started from NX Console detecting wrong platform
Current Behavior
Since today, clicking the “play” icon button in the NX Console next to project target using Vite shows this error:
Open to see error
Error: You installed esbuild for another platform than the one you're currently using. This won't work because esbuild is written with native code and needs to install a platform-specific binary executable.Specifically the “@esbuild/darwin-arm64” package is present but this platform needs the “@esbuild/darwin-x64” package instead. People often get into this situation by installing esbuild with npm running inside of Rosetta 2 and then trying to use it with node running outside of Rosetta 2, or vice versa (Rosetta 2 is Apple’s on-the-fly x86_64-to-arm64 translation service).
If you are installing with npm, you can try ensuring that both npm and node are not running under Rosetta 2 and then reinstalling esbuild. This likely involves changing how you installed npm and/or node. For example, installing node with the universal installer here should work: https://nodejs.org/en/download/. Or you could consider using yarn instead of npm which has built-in support for installing a package on multiple platforms simultaneously.
If you are installing with yarn, you can try listing both “arm64” and “x64” in your “.yarnrc.yml” file using the “supportedArchitectures” feature: https://yarnpkg.com/configuration/yarnrc/#supportedArchitectures Keep in mind that this means multiple copies of esbuild will be present.
Another alternative is to use the “esbuild-wasm” package instead, which works the same way on all platforms. But it comes with a heavy performance cost and can sometimes be 10x slower than the “esbuild” package, so you may also not want to do that.
at generateBinPath (/Users/me/galaxy/node_modules/.pnpm/esbuild@0.17.5/node_modules/esbuild/lib/main.js:1873:17)
at esbuildCommandAndArgs (/Users/me/galaxy/node_modules/.pnpm/esbuild@0.17.5/node_modules/esbuild/lib/main.js:1954:33)
at ensureServiceIsRunning (/Users/me/galaxy/node_modules/.pnpm/esbuild@0.17.5/node_modules/esbuild/lib/main.js:2118:25)
at build (/Users/me/galaxy/node_modules/.pnpm/esbuild@0.17.5/node_modules/esbuild/lib/main.js:2010:26)
at bundleConfigFile (file:///Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-f7d05e3f.js:64323:26)
at loadConfigFromFile (file:///Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-f7d05e3f.js:64299:31)
at resolveConfig (file:///Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-f7d05e3f.js:63908:34)
at _createServer (file:///Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-f7d05e3f.js:63192:26)
at Module.createServer (file:///Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/dist/node/chunks/dep-f7d05e3f.js:63189:12)
at /Users/me/galaxy/node_modules/.pnpm/vite@4.3.4_@types+node@18.14.2_less@4.1.3_sass@1.62.1_stylus@0.55.0/node_modules/vite/index.cjs:23:55
Please note that VS Code updated today which was prior to me noticing this issue, so maybe this is contributing somehow.
Also note that running the equivalent NX target via the command line (be it from VS Code or iTerm) works flawlessly, so it seems to be related to the process that NX Console spins up.
While attempting to address the above esbuild error—which I had seen before and is usually fixed by reinstalling node_modules, but not this time—I ensured that everything about my platform was not installed via Rosetta 2, as I have an M2 chip.
After reinstalling nvm, node, pnpm, VS Code and NX Console, and ensuring they are on arm64, I reran pnpm i on my workspace and got the same error. Then, I ran nx migrate latest, after which the error has changed to this:
> NX Missing Platform Dependency
The Nx CLI could not find or load the native binary for your supported platform (darwin-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/ci/troubleshoot-nx-install-issues
I did follow the troubleshooting tips in that link and ensured I could find @nx/nx-darwin-arm64 in my node_modules, but this did not fix the issue.
Expected Behavior
Clicking the “play” icon button in the NX Console next to project targets should work like it did yesterday. Ie. it should spin up a process and run the equivalent command.
Steps to Reproduce
- Match my environment.
- Use a generator to create a React application that uses Vite.
- Attempt to use NX Console to run its
servetarget. - See “Missing Platform Dependency” error.
I was easily able to reproduce the issue by cloning https://github.com/nrwl/nx-examples and attempting to run the apps/cart:serve target via the NX Console. The same error occurred with Yarn, which it is set up to run by default, and also after I changed it to use pnpm.
* Executing task: pnpm exec nx run cart:serve
> NX Missing Platform Dependency
The Nx CLI could not find or load the native binary for your supported platform (darwin-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/ci/troubleshoot-nx-install-issues
* The terminal process "/bin/zsh '-l', '-c', 'pnpm exec nx run cart:serve'" terminated with exit code: 1.
* Terminal will be reused by tasks, press any key to close it.
Environment
- Platform:
Chip Apple M2 Pro MacOS 13.2.1 (22D68)
- Nx Console version:
v18.4.0
- VSCode version (I tried others also, such as the Apple Silicon version and Insiders, with the same result):
Version: 1.80.0 (Universal) Commit: 660393deaaa6d1996740ff4880f1bad43768c814 Date: 2023-07-04T13:39:33.766Z Electron: 22.3.14 ElectronBuildId: 21893604 Chromium: 108.0.5359.215 Node.js: 16.17.1 V8: 10.8.168.25-electron.0 OS: Darwin arm64 22.3.0
- NX Report:
Node : 18.15.0 OS : darwin-arm64 pnpm : 8.6.6 nx (global) : 16.3.2 nx : 16.5.0 @nx/js : 16.5.0 @nx/jest : 16.5.0 @nx/linter : 16.5.0 @nx/workspace : 16.5.0 @nx/cypress : 16.5.0 @nx/devkit : 16.5.0 @nx/esbuild : 16.5.0 @nx/eslint-plugin : 16.5.0 @nx/plugin : 16.5.0 @nx/react : 16.5.0 @nx/vite : 16.5.0 @nx/webpack : 16.5.0 nx-cloud : 16.0.5 typescript : 5.1.6
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 4
- Comments: 46 (5 by maintainers)
This command fixed for me, basically i am using NVM~~~
I had this problem because I use NVM.
My original ‘system’ Node version before I installed NVM is the one that was being used by the VSCode task, which seems silly but is actually the one that appears in your PATH before NVM takes over.
I fixed this problem by
nvm use systemwhich switches to the base Node version and then downloading and running a Node installer for lts/hydrogen.These links gave me clues: https://stackoverflow.com/questions/44700432/visual-studio-code-to-use-node-version-specified-by-nvm https://bobbyhadz.com/blog/set-default-node-version-with-nvm#seeing-the-old-nodejs-version-in-vs-code
Solved! Thank you @TomWhiteIMO for your comment and links.
By changing the tasks.json debugging command (suggested far above by @Cammisuli - thank you) to run
which nodeI was able to see the path to the problematic Node installation VS Code’s task API was using. In my case, it was from abrewinstallation that I think I had aliased to/usr/local/bin/nodeat some point. Also, it’s likely that that version was installed on an Intel machine prior to moving to a new M2 Mac, which might explain the incorrect platform detection.Tl;dr: I ran
rm -rf /usr/local/bin/nodethen the NX Console tasks immediately worked because VS Code used the preferrednvminstallation of Node.Here is the project’s .vscode/tasks.json file I used to help debug this. You can run via Cmd-P then type
task shell. It will output the path to the Node that VS Code uses to run the task.This was my issue too, thanks 😃 Same mistake with NVM
I’m seeing this error on
npm installafter upgrading to@nx/from@nrwl/.One thing to note is that
@nrwl/clididn’t get upgraded:My current package.json
I’m going to try to upgrade that to
@nx/cli 16.5.2and see if it works.I just downloaded the previous version of VS Code (1.79.2) and the error does not occur. So it’s definitely something to do with the recent VS Code update, somehow.