balena-io / balena-sdk

The SDK to make balena powered JavaScript applications.
https://www.balena.io/
Apache License 2.0
146 stars 46 forks source link

Etcher SDK Issue in windows #1416

Closed ponmani-axim closed 1 month ago

ponmani-axim commented 1 month ago

Etcher SDK : 9.0.11 Node.js v18.20.2 OS : Windows

This is our sample node.js source code

const { Flasher, SourceDestination } = require('etcher-sdk');
const { promisify } = require('util');

// Define the path to the operating system image file
const imagePath =  "os downlaoded to my local path from https://www.debian.org/download site";

// Define the path to the target storage device (E drive in this case)
const destinationPath = 'E:\\';

async function flashOS() {
  // Create a new Flasher instance
  const flasher = new Flasher();

  try {
    // Open the source image
    const source = new SourceDestination({ path: imagePath });
    await source.open();

    // Open the destination drive (E drive)
    const destination = new SourceDestination({ path: destinationPath, overwrite: true });
    await destination.open();

    // Flash the operating system image to the destination drive
    await flasher.flash({ source, destination });

    console.log('Operating system image flashed successfully to', destinationPath);
  } catch (error) {
    console.error('Error flashing operating system image:', error);
  } finally {
    // Clean up: close the source and destination
    if (source) await promisify(source.close)();
    if (destination) await promisify(destination.close)();
  }
}

// Call the function to flash the OS
flashOS();

Error we received:

D:\Projects\Projects\sample>node writeSample.js
D:\Projects\Projects\sample\node_modules\ext2fs\lib\libext2fs.js:1
var Module=typeof Module!="undefined"?Module:{};const objects=new Map;let nextId=0;const idPool=[];function reserveId(){if(idPool.length===0){nextId+=1;idPool.push(nextId)}return idPool.shift()}function releaseId(id){idPool.push(id)}function setObject(obj){const id=reserveId();objects.set(id,obj);

 ......

TypeError: Flasher is not a constructor
    at flashOS (D:\Projects\Projects\sample\write4.js:12:19)
    at Object.<anonymous> (D:\Projects\Projects\sample\writeSample.js:37:1)
    at Module._compile (node:internal/modules/cjs/loader:1364:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1422:10)
    at Module.load (node:internal/modules/cjs/loader:1203:32)
    at Module._load (node:internal/modules/cjs/loader:1019:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12)
    at node:internal/main/run_main_module:28:49

Node.js v18.20.2