Hi ,
I’m trying to bundle a flash program using the Etcher-SDK with Webpack, but I’m running into an issue with the xxhash-addon
during the bundling process. Specifically, I get the following error:
ERROR in ./node_modules/xxhash-addon/xxhash-addon.js
Code I’m Trying to Bundle
const sdk = require("etcher-sdk");
async function handleOSFlash(
sourceImgPath,
destinationsPath,
verify = false,
numBuffers = 16
) {
function onFail(error) {
console.error("Failed to write:", error);
}
function onProgress(state) {
console.log("Progress:", state);
}
try {
console.log(sourceImgPath, destinationsPath, verify);
const source = new sdk.sourceDestination.File({
path: sourceImgPath,
});
const destinationNew = new sdk.sourceDestination.BlockDevice({
drive: JSON.parse(destinationsPath),
write: true,
direct: true,
unmountOnSuccess: false,
keepOriginal: false,
});
await sdk.multiWrite.pipeSourceToDestinations({
source: source,
destinations: [destinationNew],
onFail: onFail,
onProgress: onProgress,
verify: verify,
numBuffers: numBuffers,
});
} catch (error) {
console.error("Error while flashing", error);
}
}
if (require.main === module) {
const args = process.argv.slice(2);
if (args.length !== 3) {
console.error("Missing params <imagePath> <drive> <verify>");
process.exit(1);
}
handleOSFlash(args[0], args[1], args[2]);
}
module.exports = handleOSFlash;
Webpack Configuration
const path = require('path');
module.exports = {
entry: './flashonSDK.js',
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'dist'),
libraryTarget: 'commonjs2',
},
target: 'node',
mode: 'production',
externals: {
'winusb-driver-generator': 'commonjs winusb-driver-generator',
},
module: {
rules: [
{
test: /\.node$/,
use: 'node-loader',
},
],
},
};
Problem Description
I’m able to run the script in a non-bundled format, but when trying to bundle it using Webpack, I hit the following error:
ERROR in ./node_modules/xxhash-addon/xxhash-addon.js
It seems related to xxhash-addon
, which is used by etcher-sdk
. Has anyone successfully bundled etcher-sdk
using Webpack or had similar issues with native modules like xxhash-addon
?
Any guidance or suggestions on how to resolve this issue would be greatly appreciated. I’m wondering if there’s a way to get an Etcher-SDK package as a pre-bundled file (e.g., bundle.js
) using Webpack or another approach.
Thanks in advance for your help!