-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix: bun runtime silently returns empty object for NAPI (#28)
- Loading branch information
Showing
1 changed file
with
11 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,11 @@ | ||
module.exports = require('./lib/api')(require('node-gyp-build')(__dirname)) | ||
const nativeAddon = require('node-gyp-build')(__dirname) | ||
if (typeof nativeAddon !== 'function') { | ||
// Some new runtimes (bun) don't support N-API | ||
// but the build step incorrectly succeeds. | ||
// The value should be a function, but in bun it returns | ||
// an empty object {} so we use typeof to check that | ||
// it is a function and throw otherwise. | ||
// This throw will cause "keccak" import to fallback to JS. | ||
throw new Error('Native add-on failed to load') | ||
} | ||
module.exports = require('./lib/api')(nativeAddon) |