summaryrefslogtreecommitdiff
path: root/cli/main.rs
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2024-10-01 22:49:32 +0100
committerGitHub <noreply@github.com>2024-10-01 21:49:32 +0000
commitf9300004152ba4b3d091beb04d74f37b3b8ec281 (patch)
tree78ab2c9c6241a95ac7dbfce1902d258ef4623df0 /cli/main.rs
parent41a70898adfc61b9020dfdfec17d374aac70d935 (diff)
feat: Add suggestion for packages using Node-API addons (#25975)
This commit adds a suggestion with information and hint how to resolve situation when user tries to run an npm package with Node-API addons using global cache (which is currently not supported). Closes https://github.com/denoland/deno/issues/25974
Diffstat (limited to 'cli/main.rs')
-rw-r--r--cli/main.rs25
1 files changed, 25 insertions, 0 deletions
diff --git a/cli/main.rs b/cli/main.rs
index c0eccab5d..31bebc882 100644
--- a/cli/main.rs
+++ b/cli/main.rs
@@ -392,6 +392,31 @@ fn get_suggestions_for_terminal_errors(e: &JsError) -> Vec<FixSuggestion> {
"Run again with `--unstable-webgpu` flag to enable this API.",
),
];
+ // Try to capture errors like:
+ // ```
+ // Uncaught Error: Cannot find module '../build/Release/canvas.node'
+ // Require stack:
+ // - /.../deno/npm/registry.npmjs.org/canvas/2.11.2/lib/bindings.js
+ // - /.../.cache/deno/npm/registry.npmjs.org/canvas/2.11.2/lib/canvas.js
+ // ```
+ } else if msg.contains("Cannot find module")
+ && msg.contains("Require stack")
+ && msg.contains(".node'")
+ {
+ return vec![
+ FixSuggestion::info_multiline(
+ &[
+ "Trying to execute an npm package using Node-API addons,",
+ "these packages require local `node_modules` directory to be present."
+ ]
+ ),
+ FixSuggestion::hint_multiline(
+ &[
+ "Add `\"nodeModulesDir\": \"auto\" option to `deno.json`, and then run",
+ "`deno install --allow-scripts=npm:<package> --entrypoint <script>` to setup `node_modules` directory."
+ ]
+ )
+ ];
}
}