alanshaw / ipfs-only-hash

#️⃣ Just enough code to calculate the IPFS hash for some data
MIT License
135 stars 28 forks source link

Getting two errors: TextEncoder is not defined, Content was invalid #17

Closed terrytech closed 2 years ago

terrytech commented 3 years ago

I'm running a simple method in my code, and running into a strange error after moving to the latest library version 4.0.0

const data = 'hello world!';
const hash = await Hash.of(data);

ReferenceError: TextEncoder is not defined
      at Object.of (node_modules/ipfs-only-hash/index.js:13:5)

If I pass in a buffer as I originally needed, I get:

 Content was invalid

      79 |     const data = 'hello world!';
      80 |
    > 81 |     const hash = await Hash.of(Buffer.from(data));

I've verified I'm using the latest version. From my package-lock.json file:

 "node_modules/ipfs-only-hash": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/ipfs-only-hash/-/ipfs-only-hash-4.0.0.tgz",
      "integrity": "sha512-TE1DZCvfw8i3gcsTq3P4TFx3cKFJ3sluu/J3XINkJhIN9OwJgNMqKA+WnKx6ByCb1IoPXsTp1KM7tupElb6SyA==",
      "dependencies": {
        "ipfs-unixfs-importer": "^7.0.1",
        "meow": "^9.0.0"
      },
      "bin": {
        "ipfs-only-hash": "cli.js"
      }
    },
alanshaw commented 2 years ago

Please use Node.js v11+