ava-labs / avalanche-wallet-sdk

A Typescript library to create and manage wallets on the Avalanche network.
BSD 3-Clause "New" or "Revised" License
40 stars 26 forks source link

node-fetch should ship with the non browser version #92

Open rektbuildr opened 2 years ago

rektbuildr commented 2 years ago

When attempting to run a terminal based app using version 0.17.2, I get this error:

/@avalabs/avalanche-wallet-sdk/dist/index.js:1596
            const response = yield fetch(input, Object.assign(Object.assign({}, options), { signal: controller.signal }));
                             ^

ReferenceError: fetch is not defined
    at HttpClient.<anonymous> (/@avalabs/avalanche-wallet-sdk/dist/index.js:1596:30)
    at Generator.next (<anonymous>)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:186:71
    at new Promise (<anonymous>)
    at __awaiter (/@avalabs/avalanche-wallet-sdk/dist/index.js:182:12)
    at HttpClient.fetchWithTimeout (/@avalabs/avalanche-wallet-sdk/dist/index.js:1592:16)
    at HttpClient.post (/@avalabs/avalanche-wallet-sdk/dist/index.js:1576:41)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:5450:46
    at Generator.next (<anonymous>)
    at /@avalabs/avalanche-wallet-sdk/dist/index.js:186:71
    at new Promise (<anonymous>)
    at __awaiter (/@avalabs/avalanche-wallet-sdk/dist/index.js:182:12)
    at getAddressChains (/@avalabs/avalanche-wallet-sdk/dist/index.js:5441:12)
    at HdScanner.<anonymous> (/@avalabs/avalanche-wallet-sdk/dist/index.js:7347:36)
    at Generator.next (<anonymous>)
    at fulfilled (/@avalabs/avalanche-wallet-sdk/dist/index.js:183:58)

A working solution is to install the CJS module via:

npm install node-fetch@2 Then edit @avalabs/avalanche-wallet-sdk/dist/index.js and add

const fetch = (...args) => import('node-fetch').then(({default: fetch}) => fetch(...args)); at the top of the file.

Perhaps node-fetch should be included in the node only version?

rektbuildr commented 2 years ago

@cgcardona Anyone? Is there a better solution for Node usage? Thanks