Commit 19da4cb
fix(runtime): suggest --allow-scripts for
## Problem
Importing an npm package that relies on a native addon (e.g.
`npm:libxmljs`, pulled in by `npm:xsd-validator`) fails with:
```
error: Uncaught (in promise) Error: Could not locate the bindings file. Tried:
→ .../node_modules/libxmljs/build/xmljs.node
→ .../node_modules/libxmljs/build/Release/xmljs.node
...
at bindings (.../node_modules/bindings/bindings.js:96:9)
```
The compiled `.node` file is missing because the npm lifecycle (build)
scripts were not run. Deno already detects this situation and prints an
actionable hint ("…run `deno install --allow-scripts` to setup
`node_modules`"), but only for the Node-style `Cannot find module
'…/build/Release/xxx.node'` / `Require stack:` error.
The extremely common
[`bindings`](https://www.npmjs.com/package/bindings) npm package (used
by libxmljs and many other native addons) throws a *different* message —
`Could not locate the bindings file. Tried: …` — so the helpful
suggestion was never shown, leaving users stuck.
## Fix
Extend the native-addon error detection in
`get_suggestions_for_terminal_errors` to also match the `bindings`
package error message, so the same `--allow-scripts` / `nodeModulesDir`
hint is surfaced.
## Test
Added a spec test (`tests/specs/run/node_addon_bindings_suggestion`)
that reproduces the `bindings` error message and asserts the suggestion
is emitted.
Closes #27933
Closes denoland/divybot#396
Co-authored-by: divybot <divybot@users.noreply.github.com>
Co-authored-by: Divy Srivastava <me@littledivy.com>bindings native addon error (#34666)1 parent 75c1ba0 commit 19da4cb
4 files changed
Lines changed: 38 additions & 2 deletions
File tree
- runtime
- tests/specs/run/node_addon_bindings_suggestion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
463 | 463 | | |
464 | 464 | | |
465 | 465 | | |
466 | | - | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
467 | 474 | | |
468 | | - | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
469 | 478 | | |
470 | 479 | | |
471 | 480 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
0 commit comments