Both ncc and electron-forge rely on @vercel/webpack-asset-relocator-loader to locate and copy native node assets.
@vercel/webpack-asset-relocator-loader supports many conventions, works with wildcards, __dirname and has special cases for historic ways to load a native binary (ie. require('bindings')(...), nbind.init(..), etc). However, it's analysis fails to make sense of the binding loading code in @node-rs/helper because it's too complex.
To reproduce:
package.json
{
"name": "ncc-test",
"version": "1.0.0",
"main": "dist/index.js",
"license": "MIT",
"scripts": {
"start": "node ./dist/index.js -v",
"build": "ncc build index.js -o dist"
},
"devDependencies": {
"@vercel/ncc": "^0.27.0"
},
"dependencies": {
"@node-rs/crc32": "^1.0.0"
}
}
index.js
const crc = require("@node-rs/crc32");
const out = crc.crc32(Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]));
console.log("out", out);
Run
yarn && yarn build && yarn run
Result:
Can not find node binding files from @node-rs/crc32-darwin-x64 and /Users/timfish/Documents/Repositories/ncc-test/dist/crc32.darwin-x64.node
Both
nccandelectron-forgerely on@vercel/webpack-asset-relocator-loaderto locate and copy native node assets.@vercel/webpack-asset-relocator-loadersupports many conventions, works with wildcards,__dirnameand has special cases for historic ways to load a native binary (ie.require('bindings')(...),nbind.init(..), etc). However, it's analysis fails to make sense of the binding loading code in@node-rs/helperbecause it's too complex.To reproduce:
package.json{ "name": "ncc-test", "version": "1.0.0", "main": "dist/index.js", "license": "MIT", "scripts": { "start": "node ./dist/index.js -v", "build": "ncc build index.js -o dist" }, "devDependencies": { "@vercel/ncc": "^0.27.0" }, "dependencies": { "@node-rs/crc32": "^1.0.0" } }index.jsRun
Result:
Can not find node binding files from @node-rs/crc32-darwin-x64 and /Users/timfish/Documents/Repositories/ncc-test/dist/crc32.darwin-x64.node