Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

425
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!