Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

428
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda