diff --git a/docs/shared/installation/troubleshoot-installation.md b/docs/shared/installation/troubleshoot-installation.md index 5a9e04c497547..2f6546e3242ce 100644 --- a/docs/shared/installation/troubleshoot-installation.md +++ b/docs/shared/installation/troubleshoot-installation.md @@ -22,7 +22,16 @@ When updating Nx that is already on 15.8, the package-lock.json should continue ### How to fix 1. If you are running your install command with `--no-optional`, try again without the flag. -2. Delete your node_modules and `package-lock.json` and re-run `npm i`. This should have the `package-lock.json` file updated properly. +1. Delete your node_modules and `package-lock.json` (or other lock files) and re-run your package manager's install command. +1. If running on Windows, make sure that the [installed Microsoft Visual C++ Redistributable is up-to-date](https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads). + +Confirm that you see `@nx/nx-plaform-arch` in your `node_modules` folder (e.g. `@nx/nx-darwin-arm64`, `@nx/nx-win32-x64-msvc`, etc). + +If you are still experiencing issues after following the previous steps, please [open an issue on Github](https://github.com/nrwl/nx/issues/new?assignees=&labels=type:+bug&projects=&template=1-bug.yml) and we will help you troubleshoot. +Be prepared to give as much detail as possible about your system, we will need the following information at a minimum, the contents of `nx report` plus + +- Operating system version +- The package manager (npm, yarn, pnpm, etc) install command ### Supported native module platforms diff --git a/packages/nx/bin/nx.ts b/packages/nx/bin/nx.ts index df57c8f6d4d76..eca286d781f55 100644 --- a/packages/nx/bin/nx.ts +++ b/packages/nx/bin/nx.ts @@ -15,22 +15,15 @@ import { stripIndents } from '../src/utils/strip-indents'; import { readModulePackageJson } from '../src/utils/package-json'; import { execSync } from 'child_process'; import { join } from 'path'; +import { assertSupportedPlatform } from '../src/native/assert-supported-platform'; function main() { if ( process.argv[2] !== 'report' && process.argv[2] !== '--version' && - process.argv[2] !== '--help' && - !_supportedPlatform() + process.argv[2] !== '--help' ) { - output.error({ - title: 'Platform not supported', - bodyLines: [ - `This platform (${process.platform}-${process.arch}) is currently not supported by Nx.`, - 'For a list of supported platforms, please see https://nx.dev/recipes/ci/troubleshoot-nx-install-issues#supported-native-module-platform', - ], - }); - process.exit(1); + assertSupportedPlatform(); } const workspace = findWorkspaceRoot(process.cwd()); @@ -256,15 +249,6 @@ function _getLatestVersionOfNx(): string { } } -function _supportedPlatform(): boolean { - try { - require('../src/native'); - return true; - } catch { - return false; - } -} - const getLatestVersionOfNx = ((fn: () => string) => { let cache: string = null; return () => cache || (cache = fn()); diff --git a/packages/nx/bin/compute-project-graph.ts b/packages/nx/bin/post-install.ts similarity index 90% rename from packages/nx/bin/compute-project-graph.ts rename to packages/nx/bin/post-install.ts index 19bcabfd73b66..b48154b662888 100644 --- a/packages/nx/bin/compute-project-graph.ts +++ b/packages/nx/bin/post-install.ts @@ -3,10 +3,13 @@ import { workspaceRoot } from '../src/utils/workspace-root'; import { fileExists } from '../src/utils/fileutils'; import { join } from 'path'; import { daemonClient } from '../src/daemon/client/client'; +import { assertSupportedPlatform } from '../src/native/assert-supported-platform'; (async () => { try { if (isMainNxPackage() && fileExists(join(workspaceRoot, 'nx.json'))) { + assertSupportedPlatform(); + try { await daemonClient.stop(); } catch (e) {} diff --git a/packages/nx/package.json b/packages/nx/package.json index 25dfe247ded9e..fc40c07e5cac8 100644 --- a/packages/nx/package.json +++ b/packages/nx/package.json @@ -9,7 +9,7 @@ "directory": "packages/nx" }, "scripts": { - "postinstall": "node ./bin/compute-project-graph" + "postinstall": "node ./bin/post-install" }, "keywords": [ "Monorepo", diff --git a/packages/nx/src/native/assert-supported-platform.ts b/packages/nx/src/native/assert-supported-platform.ts new file mode 100644 index 0000000000000..1125d2ef3e22d --- /dev/null +++ b/packages/nx/src/native/assert-supported-platform.ts @@ -0,0 +1,40 @@ +import { output } from '../utils/output'; + +export function assertSupportedPlatform() { + try { + require('./index.js'); + } catch (e) { + let title = ''; + let bodyLines = []; + if ( + process.platform == 'win32' || + process.platform == 'darwin' || + process.platform == 'linux' || + process.platform == 'freebsd' + ) { + title = 'Missing Platform Dependency'; + bodyLines = [ + `The Nx CLI could not find or load the native binary for your supported platform (${process.platform}-${process.arch}).`, + 'This likely means that optional dependencies were not installed correctly, or your system is missing some system dependencies.', + ]; + if (process.env.NX_VERBOSE_LOGGING == 'true') { + bodyLines.push('', 'Additional error information:', e.message); + } + } else { + title = 'Platform not supported'; + bodyLines = [ + `This platform (${process.platform}-${process.arch}) is currently not supported by Nx.`, + ]; + } + + bodyLines.push( + 'For more information please see https://nx.dev/recipes/ci/troubleshoot-nx-install-issues' + ); + + output.error({ + title, + bodyLines, + }); + process.exit(1); + } +}