Skip to content

Commit

Permalink
Improved npm install troubleshooting messages
Browse files Browse the repository at this point in the history
Signed-off-by: Prabhu Subramanian <[email protected]>
  • Loading branch information
prabhu committed Dec 13, 2024
1 parent 4861eba commit 855da91
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.7",
"version": "11.0.8",
"exports": "./lib/cli/index.js",
"compilerOptions": {
"lib": ["deno.window"],
Expand Down
2 changes: 1 addition & 1 deletion jsr.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.7",
"version": "11.0.8",
"exports": "./lib/cli/index.js",
"include": ["*.js", "lib/**", "bin/**", "data/**", "types/**"],
"exclude": [
Expand Down
37 changes: 33 additions & 4 deletions lib/cli/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
unlinkSync,
writeFileSync,
} from "node:fs";
import { platform as _platform, homedir, tmpdir } from "node:os";
import { platform as _platform, arch, homedir, tmpdir } from "node:os";
import { basename, dirname, join, resolve, sep } from "node:path";
import process from "node:process";
import { URL } from "node:url";
Expand Down Expand Up @@ -2391,9 +2391,18 @@ export async function createNodejsBom(path, options) {
});
if (result.status !== 0 || result.error) {
console.error(
`${pkgMgr} install has failed. Check if ${pkgMgr} is installed and available in PATH.`,
`${pkgMgr} install has failed. Generated SBOM will be empty or with a lower precision.`,
);
if (DEBUG_MODE && result.stdout) {
if (result.stdout.includes("EBADENGINE Unsupported engine")) {
console.log(
"Try using the custom `ghcr.io/cyclonedx/cdxgen-node20:v11` container image, which bundles node.js 20. The current version of node.js is incompatible for this project.",
);
console.log(
"Alternatively, run cdxgen with the custom node with version types. Eg: `-t node20`",
);
}
console.log("---------------");
console.log(result.stdout);
}
if (result.stderr) {
Expand All @@ -2402,11 +2411,31 @@ export async function createNodejsBom(path, options) {
"Set the environment variable `NPM_INSTALL_ARGS=--legacy-peer-deps` to resolve the dependency resolution issue reported.",
);
}
if (result.stderr.includes("EBADENGINE Unsupported engine")) {
if (
result.stderr.includes(
"npm error command sh -c node-pre-gyp install",
)
) {
console.log(
"Try using the custom `ghcr.io/cyclonedx/cdxgen-node20:v11` container image, which bundles node.js 20.",
"cdxgen has detected errors with the native build using node-gyp.",
);
if (process.env?.CDXGEN_IN_CONTAINER === "true") {
if (arch() !== "x64") {
console.log(
`INFO: Many npm packages have limited support for ${arch()} architecture.\nRun the cdxgen container image with --platform=linux/amd64 for best experience.`,
);
} else {
console.log(
"Try using the custom `ghcr.io/cyclonedx/cdxgen-node20:v11` container image, which bundles node.js 20. The default image bundles node >= 23, which might be incompatible.",
);
}
} else {
console.log(
"Try using the custom `ghcr.io/cyclonedx/cdxgen-node20:v11` container image with --platform=linux/amd64, which bundles node.js 20.",
);
}
}
console.log("---------------");
console.log(result.stderr);
}
options.failOnError && process.exit(1);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cyclonedx/cdxgen",
"version": "11.0.7",
"version": "11.0.8",
"description": "Creates CycloneDX Software Bill of Materials (SBOM) from source or container image",
"homepage": "http://github.com/cyclonedx/cdxgen",
"author": "Prabhu Subramanian <[email protected]>",
Expand Down
2 changes: 1 addition & 1 deletion types/lib/cli/index.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 855da91

Please sign in to comment.