[bluetooth-adapter] - TypeError: Noble__default is not a constructor
I am using @node-escpos/core, @node-escpos/network-adapter, @node-escpos/bluetooth-adapter in my electron.js, react project. network adapter working fine. but when i call Bluetooth it give me the following error.
TypeError: Noble__default is not a constructor
at Object.
here is my implementation on main process
import Bluetooth from '@node-escpos/bluetooth-adapter'; ipcMain.handle('bt-print', async (_event, { port }) => { try { const device = new Bluetooth(port, {});
} catch (error) { console.log(error);
}
});
Hi @aargon007! I'm Dosu and I’m helping the driver team.
The error happens because the Bluetooth adapter tries to use new Noble(), but the @abandonware/noble library is a singleton module, not a constructor. This means you should use the imported Noble object directly, not instantiate it with new—the current adapter code is fundamentally incompatible with how noble is meant to be used, which leads to the TypeError: Noble__default is not a constructor in Electron and Node.js environments. This is a known issue with the adapter's implementation and not something you can fix with import settings or TypeScript config alone.
More details: bluetooth-adapter source
To work around this, you would need to patch the adapter code to use the Noble object as a singleton (remove new Noble(...) and use Noble directly). There is no official workaround or fix published yet. This kind of native module and ESM/CJS interop issue is also common in Electron environments, especially with hardware libraries like noble.
Related discussion: issue 77
To reply, just mention @dosu.
How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other