从ES6模块转换的问题



我已经做了下面的脚本,它允许我在NFT上上传图像。存储ipfs服务器并检索img url

import { NFTStorage, File } from "nft.storage"
import { mime } from "mime"
import { fs } from "fs"
import { path } from "path"
import { fetch } from "node-fetch"
async function storeNFT(imagePath, name, description) { 
const image = await fileFromPath(imagePath)
const NFT_STORAGE_KEY = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJkaWQ6ZXRocjoweDk5ZmJBOWU3ZTg3RjlENUExZDA3QTJDQTlmNDE4ODNBMGYwNzkyRjgiLCJpc3MiOiJuZnQtc3RvcmFnZSIsImlhdCI6MTY4MDQyNDg5MDI0MiwibmFtZSI6IkF1cm9uQ3JvdyJ9.t7oqb2D9kMYRV1wDJrIiSRNtmyTioqTeNyEjSpfDJvw'
const nftstorage = new NFTStorage({ token: NFT_STORAGE_KEY })
return nftstorage.store({
image,
name,
description,
})
}
async function fileFromPath(filePath) {
const content = await fs.promises.readFile(filePath)
const type = mime.getType(filePath)
return new File([content], path.basename(filePath), { type })
}
async function getImgUrl(imagePath, name, description) {
const result = await storeNFT(imagePath, name, description)
let myUrl = "https://ipfs.io/ipfs/" + result.url.slice(7,80)
console.log(myUrl)
let settings = { method: "Get" };
fetch(myUrl, settings)
.then(res => res.json())
.then((json) => {
console.log(json.image)
let newUrl = "https://ipfs.io/ipfs/" + json.image.slice(7,80)
console.log(newUrl)
})
}

如果我使用命令行运行代码,上传实际上成功了,我得到了我正在寻找的结果,图像Url,但是,我需要这在浏览器端工作,所以我尝试使用以下命令

使用browserify和esmify
browserify index.js -p esmify > bundle.js

但是,我得到的依赖错误如下

无法遍历依赖图:无法从'node_modulesnft.storagedistsrclib.cjs'中找到模块'ipfs-car/blockstore/fs' users a.marica desktop PersonalWorkFiverrSolidityNFT_Marketplace_PrototypeNFT_Storage_Apinode_modulesnft.storagedistsrclib.cjs

我不明白为什么它能够得到所有的依赖关系,并正确地工作,如果从命令行启动,但不是通过browserify启动,以便将其转换为正常的js

const content = await fs.promises.readFile(filePath)

浏览器不提供从文件路径读取文件的api(它们提供<input type="file">FileReader来读取用户选择的文件)。

没有办法为browserify或类似的东西来填充。