Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

426
Visualizações
Uncaught SyntaxError: The requested module does not provide an export named 'fs'

I'm not good with javascript. I'm trying to upload a few files to nft.storage as a folder by modifying this example -> https://github.com/nftstorage/nft.storage/blob/main/packages/client/examples/node.js/storeDirectory.js

Instead of uploading via a form, my files are stored in my PC file system. Below is my js code.

<script type="module">
  import { NFTStorage, File } from 'https://cdn.skypack.dev/nft.storage'
  import { fs } from 'https://cdn.skypack.dev/fs-'

  const endpoint = 'https://api.nft.storage' // the default
  const token = 'RDA0NjI0MTIzMTA2Mzgy....' // your API key from https://nft.storage/manage

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

  document.querySelector('#upload-file-ipfs').addEventListener('click', async (e) => {
    e.preventDefault()
    
    const storage = new NFTStorage({ endpoint, token })
    const cid = await storage.storeDirectory([
        new File([await fs.promises.readFile('metadata.json')], 'metadata.json'),
        new File([await fs.promises.readFile('test.png')], 'test.png'),
    ])
    console.log({ cid })
    const status = await storage.status(cid)
    console.log(status)
  })
</script>

But I keep getting this error below.

Uncaught SyntaxError: The requested module 'https://cdn.skypack.dev/fs-' does not provide an export named 'fs'

I tried replacing 'https://cdn.skypack.dev/fs-' with 'https://www.skypack.dev/view/fs-extra' and ''https://cdn.skypack.dev/graceful-fs' and it gives me the same error.

If I remove the curly braces around 'fs', I get Uncaught Error: [Package Error] "fs" does not exist. (Imported by "fs-").

Any help is highly appreciated. My application is PHP+ JS, not node.js.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

It should be without curly braces, as shown in the docs for fs-, but the second error tells you the next problem: You are trying to use a package in the browser which is designed for node.js. (Browsers don't have a native fs module.) Use it in your backend node.js application, not the frontend.

Since you seem to be trying to use this in a browser, probably you shouldn't use the node.js example that you linked (nft.storage/packages/client/examples/node.js/storeDirectory.js) but rather the browser example: https://github.com/nftstorage/nft.storage/blob/main/packages/client/examples/browser

Remember however that a script in a browser can't just read random files from the user's file system. The user has to upload the file in a form (or give access to a certain directory using the browser file system APIs, but that's experimental).

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda