holepunchto/autobase

TypeError: Cannot read properties of null (reading 'get')

nharlow89 opened this issue · 2 comments

Running the sample code provided in the readme resulted in the following error: TypeError: Cannot read properties of null (reading 'get'). It appears that localOutput must be defined to get the linearized view via base.view.get(). Would love to submit a PR for any of the following to help with developer experience

  • Update sample code to include localOutput for completeness
  • Throw error in base.view.update() if no output is defined (wasn't obvious why update returns but get throws?)
  • Default in-memory value for localOutput if not defined
import Autobase from "autobase";
import Hypercore from "hypercore";
import ram from "random-access-memory";

const inputA = new Hypercore(ram);
const inputB = new Hypercore(ram);
const inputC = new Hypercore(ram);
const base = new Autobase({
  inputs: [inputA, inputB, inputC],
  localInput: inputA,
  autostart: true,
});
await base.append("hello");
await base.append("world");
// view.update() returns
await base.view.update();
// view.get() throws
await base.view.get(0);

Also experiencing this issue

LuKks commented

@nharlow89 @jarbus That is happening because the NPM package is outdated! I guess it will be updated soon.

For now, try installing it this way:
npm i hypercore-protocol/autobase

It will work just fine :)