Skip to content

Commit 2a40bfd

Browse files
authored
chore: Added nan handling documentation. (#4)
* chore: Added nan handling documentation. Signed-off-by: Paolo Insogna <paolo@cowtech.it> * fixup Signed-off-by: Paolo Insogna <paolo@cowtech.it> * fixup Signed-off-by: Paolo Insogna <paolo@cowtech.it> --------- Signed-off-by: Paolo Insogna <paolo@cowtech.it>
1 parent 8a98439 commit 2a40bfd

1 file changed

Lines changed: 33 additions & 1 deletion

File tree

README.md

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,39 @@ Memory comparison between standard Node.js 22 and pointer-compressed Node.js 25
9393
| `@napi-rs/uuid` | Rust N-API | ✓ Works |
9494
| `@node-rs/argon2` | Rust N-API | ✓ Works |
9595

96-
**Non-N-API native addons may crash.** Addons using the older V8 native addon API (like `better-sqlite3`) are not compatible with pointer compression and will segfault. Always prefer N-API-based alternatives.
96+
**Non-N-API native addons may crash.** Addons using the older V8 native addon API (like `better-sqlite3`) are not compatible with pointer compression and can segfault. Packages that rely on `nan` are especially affected. Always prefer N-API-based alternatives.
97+
98+
### Workarounds for Non-N-API Addons
99+
100+
If your dependency uses `nan` and does not provide binaries built for this runtime, you must force a local rebuild of its native addon.
101+
102+
If the package in `node_modules` still contains source files, try a normal rebuild:
103+
104+
```bash
105+
cd node_modules/<package-name>
106+
pnpm install --ignore-scripts
107+
pnpm run rebuild
108+
```
109+
110+
Some packages on npm do not ship source files needed to rebuild. In these cases, you may need to fetch the source from the git repository, copy it back into `node_modules`, and run a manual rebuild.
111+
112+
#### Known affected package example
113+
114+
##### `@datadog/pprof`
115+
116+
This was tested against [@datadog/pprof](https://www.npmjs.com/package/@datadog/pprof) 5.13.5.
117+
118+
```bash
119+
cd node_modules/@datadog/pprof
120+
pnpm install --ignore-scripts
121+
PPROF_VERSION=$(node -p "require('./package.json').version")
122+
PPROF_REPO=$(node -p "require('./package.json').repository.url.replace('git+', '')")
123+
git clone -q --depth=1 --branch=v$PPROF_VERSION $PPROF_REPO /tmp/pprof-nodejs > /dev/null 2>&1
124+
mv /tmp/pprof-nodejs/{binding.gyp,bindings} .
125+
rm -rf /tmp/pprof-nodejs
126+
pnpm run rebuild
127+
cd ../../..
128+
```
97129

98130
## How It Works
99131

0 commit comments

Comments
 (0)