abandonware / noble

A Node.js BLE (Bluetooth Low Energy) central module : Community maintained
https://libraries.io/npm/@abandonware%2Fnoble
MIT License
532 stars 160 forks source link

TypeError: require(...) is not a constructor error with -12 version on macOS Catalina? #186

Open Patronics opened 3 years ago

Patronics commented 3 years ago

Running macOS Catalina 10.15.7 and noble 1.9.2-12 with either node 12 and node 14 fails with this error:

patrickleiser$ node bluetooth.js 
/Users/username/path/to/project/node_modules/@abandonware/noble/lib/resolve-bindings.js:11
    return new (require('./mac/bindings'))(options);
           ^

TypeError: require(...) is not a constructor
    at module.exports (/Users/username/path/to/project/node_modules/@abandonware/noble/lib/resolve-bindings.js:11:12)
    at Object.<anonymous> (/Users/username/path/to/project/node_modules/@abandonware/noble/index.js:2:51)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at Object.<anonymous> (/Users/username/path/to/project/bluetooth.js:7:15)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)

It also seems to fail to connect to devices, despite not throwing the error, on a debian linux system.

However, version 1.9.2-11 does work fine for both devices in the same circumstances.

peterlcsteele commented 3 years ago

Same issue experienced on Mojave. Reversion to -11 resolves the issue.

ralpioxxcs commented 3 years ago

I have same problem too.

rzr commented 3 years ago

regression might come from @atrovato's change:

https://github.com/abandonware/noble/commit/743b97551708ffc1392dc65d3f80db39238b8ac6#diff-5f8789720a0cb32cd50bd1f2ac87089febed143de711df08eb6cd610d44bb9c1R11

I wish it would have been triggered by CI , please can you try improve tests ?

atrovato commented 3 years ago

I will, asap.

atrovato commented 3 years ago

@rzr testing will be difficult, please see https://github.com/abandonware/noble/pull/188/checks?check_run_id=2034662987

atrovato commented 3 years ago

Ok, PR is ready, I do tests with proxyquire to simulate all envs.