Skip to content

Commit

Permalink
fix(core): improve error message when native binaries are not found f…
Browse files Browse the repository at this point in the history
…or a supported platform (#17817)

(cherry picked from commit fc4b6a8)
  • Loading branch information
Cammisuli authored and FrozenPandaz committed Jun 29, 2023
1 parent 5a42215 commit 0b5cb5b
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 21 deletions.
11 changes: 10 additions & 1 deletion docs/shared/installation/troubleshoot-installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 3 additions & 19 deletions packages/nx/bin/nx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"directory": "packages/nx"
},
"scripts": {
"postinstall": "node ./bin/compute-project-graph"
"postinstall": "node ./bin/post-install"
},
"keywords": [
"Monorepo",
Expand Down
40 changes: 40 additions & 0 deletions packages/nx/src/native/assert-supported-platform.ts
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 0b5cb5b

Please sign in to comment.