NebulousLabs / nodejs-skynet

Library for integrating Skynet into Node.js applications
MIT License
29 stars 12 forks source link

UnhandledPromiseRejectionWarning: TypeError: skynet.uploadFile is not a function #47

Closed ltfschoen closed 4 years ago

ltfschoen commented 4 years ago

I've tried this with both Node.js 14.7.0 and v12.18.3 and both encounter the same error. The README says to refer to the docs here https://github.com/NebulousLabs/nodejs-skynet#documentation I added the dependency by running yarn add @nebulous/skynet https://github.com/NebulousLabs/nodejs-skynet#installing, but it appears to install an older version from ~5 months ago into node_modules/, even though the version shown in the package.json in node_modules/ is 1.0.1 (the same as in the latest 'master'). And the latest documentation uses the latest code from the 'master' branch instead of the latest code published at NPM. If I even just try the example code at "Making Your First API Call" https://nebulouslabs.github.io/skynet-docs/?javascript#making-your-first-api-call, I get the following error:

(node:28545) UnhandledPromiseRejectionWarning: TypeError: skynet.uploadFile is not a function
    at /Users/ls/code/src/ltfschoen/skyhandler/scripts/skynetUpload.js:5:34
    at Object.<anonymous> (/Users/ls/code/src/ltfschoen/skyhandler/scripts/skynetUpload.js:10:3)
    at Module._compile (internal/modules/cjs/loader.js:1137:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
    at Module.load (internal/modules/cjs/loader.js:985:32)
    at Function.Module._load (internal/modules/cjs/loader.js:878:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47

It appears to be because the code in the version that gets installed in node_modules/@nebulous/skynet on my local machine differs from the latest 'master' branch Github at https://github.com/NebulousLabs/nodejs-skynet (I assumed that was the version that's published to NPM, and I noticed that there aren't any official releases https://github.com/NebulousLabs/nodejs-skynet/releases). If I inspect the code that gets installed to node_modules/@nebulous/skynet, it's clear that the error is caused because it's exporting capitalized UploadFile (I think triggered from this commit ~5 months ago https://github.com/NebulousLabs/nodejs-skynet/commit/9e2532098a7c7128e84ac7efa7641bf1c39a3f51) instead of uploadFile that's used in the 'master' branch here https://github.com/NebulousLabs/nodejs-skynet/blob/master/src/upload.js#L20, and that code doesn't fallback to default values if the user doesn't provide all the necessary custom options as an argument to the uploadFile function (changes were made to improve this in the latest 'master'.

Also, I noticed in the latest 'master' branch that if the user doesn't provide a portalUrl property value as part of the customOptions parameter when calling uploadFile, it doesn't appear to fallback to a default value https://github.com/NebulousLabs/nodejs-skynet/blob/master/src/upload.js#L28

I was able to get it to work if modified package.json to just install the latest version from the 'master' branch (instead of it being "@nebulous/skynet": "^1.0.1", when installed using yarn add @nebulous/skynet:

  "dependencies": {
    "@nebulous/skynet": "git://github.com/NebulousLabs/nodejs-skynet.git#master",
mrcnski commented 4 years ago

Thanks for raising this @ltfschoen. We haven't published a new version in a while. We'll try to do it later today -- apologies for the inconvenience.

mrcnski commented 4 years ago

We just published v1.1.0 which you can use.