ipfs-car icon indicating copy to clipboard operation
ipfs-car copied to clipboard

Why won't it skypack

Open olizilla opened this issue 4 years ago • 5 comments

trying to use skypack like:

<!DOCTYPE html>
<head>
  <meta charset="utf-8" />
</head>
<pre id="out"></pre>
<script type="module">
  import { NFTStorage } from 'https://cdn.skypack.dev/nft.storage'
  import { packToBlob } from 'https://cdn.skypack.dev/ipfs-car/pack/blob'

  const endpoint = 'https://api.nft.storage' // the default
  const token =
    new URLSearchParams(window.location.search).get('key') || 'API_KEY' // your API key from https://nft.storage/manage

  function log(msg) {
    msg = JSON.stringify(msg, null, 2)
    document.getElementById('out').innerHTML += `${msg}\n`
  }

  async function main() {
    const store = new NFTStorage({ endpoint, token })
    const data = 'Hello nft.storage!'

    // locally chunk'n'hash the data to get the CID and pack the blocks in to a CAR
    const { root, car } = await packToBlob({
      input: [new TextEncoder().encode(data)],
    })
    const expectedCid = root.toString()
    console.log({ expectedCid })

    // send the CAR to nft.storage, the returned CID will match the one we created above.
    const cid = await store.storeCar(car)

    // verify the service is storing the CID we expect
    const cidsMatch = expectedCid === cid
    log({ data, cid, expectedCid, cidsMatch })

    // check that the CID is pinned
    const status = await store.status(cid)
    log(status)
  }
  main()
</script>

does not work. You get a

Uncaught TypeError: null has no properties
    <anonymous> https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/unoptimized/to-string.js:4
to-string.js:4:23

from:

https://cdn.skypack.dev/-/[email protected]/dist=es2020,mode=imports/unoptimized/to-string.js

but there is no obvious reason why it should pull in version 2.1.3 when there is a 2.1.5 version of unit8arrays that does not have the problem. the older version uses TextEncoder from web-encoding https://github.com/achingbrain/uint8arrays/compare/v2.1.3...v2.1.5 that fails to bundle. The newere 2.1.5 doesn't. WHY IS SKYPACK USING THE OLDER BAD ONE?

olizilla avatar Jun 15 '21 15:06 olizilla

So, I can see that skypack gets a bunch of uint8arrays and somehow one of our dependencies use the 2.1.3

image

this is related to https://github.com/skypackjs/skypack-cdn/issues/159

vasco-santos avatar Jun 23 '21 11:06 vasco-santos

@olizilla I could discover that is multicodec that apparently is pulling the old uint8arrays, even though I have no clue of the reason behind this... It is pulled from unixfs-importer

Please check https://codepen.io/vascosantos/pen/mdWZmWq?editors=0011

image

As we can see, it only gets 2.1.3...

vasco-santos avatar Jun 23 '21 11:06 vasco-santos

The multicodec PR fixed the problem mentioned on the Original Post, but now we have another issue...

Uncaught TypeError: Cannot destructure property 'sha256' of 'require$$1' as it is null.
    at ipfs-unixfs-importer.js:18

This is in the unixfs-importer now: https://codepen.io/vascosantos/pen/LYWwgPP?editors=0011

vasco-santos avatar Jun 25 '21 08:06 vasco-santos

Some research happened on: https://github.com/vasco-santos/cjs-esm-skypack-build-rep

And root issue updated: https://github.com/skypackjs/skypack-cdn/issues/171

To unblock this, we will need to either bundle ipfs-unixfs on publish, or make it an ESM citizen

vasco-santos avatar Jul 08 '21 12:07 vasco-santos

related: https://github.com/web3-storage/web3.storage/issues/220

atopal avatar Aug 16 '21 13:08 atopal