UrielCh / adbkit

A pure Node.js client for the Android Debug Bridge.
Other
34 stars 9 forks source link

TypeError: Adb.createClient is not a function #3

Closed kkuehl closed 2 years ago

kkuehl commented 2 years ago

First, thank you so much for modernizing adbkit. Taking a look at the examples:

import Bluebird from 'bluebird';
import Adb from '@u4/adbkit';

const client = Adb.createClient();

const test = async () => {
    try {
        const devices = await client.listDevices();
        const supportedDevices = await Bluebird.filter(devices, async (device) => {
            const features = await client.getFeatures(device.id);
            return features['android.hardware.nfc'];
        });
        console.log('The following devices support NFC:', supportedDevices);
    } catch (err) {
        console.error('Something went wrong:', err.stack);
    }
};
➜  nodeadb DEBUG=adb:* node app.js
file:///home/user/code/gitlab/nodeadb/app.js:4
const client = Adb.createClient();
                   ^

TypeError: Adb.createClient is not a function
    at file:///home/user/code/gitlab/nodeadb/app.js:4:20
    at ModuleJob.run (node:internal/modules/esm/module_job:197:25)
    at async Promise.all (index 0)
    at async ESMLoader.import (node:internal/modules/esm/loader:337:24)
    at async loadESM (node:internal/process/esm_loader:88:5)
    at async handleMainPromise (node:internal/modules/run_main:61:12)
nodeadb@1.0.0 /home/user/code/gitlab/nodeadb
├── @u4/adbkit@3.1.7
├── bluebird@3.7.2
├── debug@4.3.4
├── nodemon@2.0.15
└── picocolors@1.0.0

I must be doing something trivial incorrectly.

UrielCh commented 2 years ago

I check the code:

index.ts: export { default } from './adb'; export { default as Adb } from './adb';

adb.ts:

export default class Adb {
  static util = util;

  public static createClient(options: Options = {}): Client {
    ...
    return new Client(opts);
  }
}

this part Is ok.

bluebird had been removed, in favor of the Native promises.

I use Typescript, and I did not switch to ESM yet.

so, use Typescript or CommonJS style import.

kkuehl commented 2 years ago

I have this working now, thank you!