avalanche-wallet-sdk icon indicating copy to clipboard operation
avalanche-wallet-sdk copied to clipboard

node-fetch should ship with the non browser version

Open rektbuildr opened this issue 2 years ago • 1 comments

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 avatar May 12 '22 23:05 rektbuildr

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

rektbuildr avatar May 25 '22 01:05 rektbuildr