orbitdb / field-manual

The Offical User's Guide to OrbitDB
207 stars 43 forks source link

Outdated Tutorial [Chapter 1 & 2] #173

Open mubeenghauri opened 2 years ago

mubeenghauri commented 2 years ago

I have been following the tutorial, and have been facing the following issues (these issues are mainly with IPFS, but i believe are relevant to whoever is going through the tutorial ):

1) [In chapter 1] IPFS@0.62.1 (latest version as of now) will not work with node version less then 16, i've tried running the tutorial with node v12.22.11 and v14.19.1, getting the following error :

/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/timeout-abort-controller/index.js:8
class TimeoutController extends AbortController {
                                ^

TypeError: Class extends value undefined is not a constructor or null
    at Object.<anonymous> (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/timeout-abort-controller/index.js:8:33)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
    at Module.load (internal/modules/cjs/loader.js:863:32)
    at Function.Module._load (internal/modules/cjs/loader.js:708:14)
    at Module.require (internal/modules/cjs/loader.js:887:19)
    at require (internal/modules/cjs/helpers.js:74:18)
    at Object.<anonymous> (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-core-utils/cjs/src/with-timeout-option.js:5:30)
    at Module._compile (internal/modules/cjs/loader.js:999:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)

Although I was not able to find any concrete solution to this in any of the present issues, i got it working with node v16. Whereas the tutorial says, and I quote

Note: This code was tested on Node v11.14.0. Your mileage for other versions may vary.

I tested with v.11 of node as well, that gave a completely different exception, but an exception nonetheless, therefore above is no more valid, should be updated.

2) [in chapter 2] the arguments for IPFS.CID are described as

 cid = new IPFS.CID(cid) 

( EDIT: after a bit of digging around the js-multiformat, the following code worked for me, this fixed the second issue listed below too,

cid = IPFS.CID.parse(cid)

)

This is not working, after looking more into it, i found the constructor of CID has the following parameters:

class CID {
  constructor(version, code, multihash, bytes) {

(located at node_modules/multiformats/cjs/src/cid.js)

Clearly, that line of code in the tutorial wont be working with it, after figuring out what these params mean, i got it to work.

However, the issues dont end here, currently the following line of code is also giving an exception, haven't figured this out yet,

Code:

const content = await NPP.node.dag.get(cid)

Exception:

/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/multiformats/cjs/src/bases/base.js:18
      throw Error('Unknown type, must be binary type');
            ^

Error: Unknown type, must be binary type
    at Encoder.encode (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/multiformats/cjs/src/bases/base.js:18:13)
    at Codec.encode (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/multiformats/cjs/src/bases/base.js:77:25)
    at cidToKey (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/blockstore-datastore-adapter/cjs/src/index.js:49:42)
    at BlockstoreDatastoreAdapter.has (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/blockstore-datastore-adapter/cjs/src/index.js:182:27)
    at Object.has (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-repo/cjs/src/pinned-blockstore.js:41:20)
    at Object.has (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-repo/cjs/src/idstore.js:83:20)
    at BlockStorage.has (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-core/cjs/src/block-storage.js:81:23)
    at BlockStorage.get (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-core/cjs/src/block-storage.js:52:21)
    at get (/home/mubeen/lab/obdb_tutorial/tutorial/node_modules/ipfs-core/cjs/src/components/dag/get.js:31:37)
    at async /home/mubeen/lab/obdb_tutorial/tutorial/index.js:31:21

Haven't gotten ahead of this yet, but this is what i've encountered so far. Have i miss-interpreted something, or are these tutorials really outdated ?