如何在Angular 11项目中使用nft.storage库



我有一个Angular项目,我正在尝试使用nft.storage库。但是我在Angular Cli中得到了以下错误:

Error: ./node_modules/nft.storage/src/platform.web.js
Module not found: Error: Can't resolve 'ipfs-car/blockstore/memory' in '/home/newsha/Newsha/sonido-project/Sonido-front/node_modules/nft.storage/src'
Error: ./node_modules/nft.storage/src/lib.js
Module not found: Error: Can't resolve 'ipfs-car/pack' in '/home/newsha/Newsha/sonido-project/Sonido-front/node_modules/nft.storage/src'
Error: ./node_modules/nft.storage/src/token.js
Module not found: Error: Can't resolve 'ipfs-car/pack' in '/home/newsha/Newsha/sonido-project/Sonido-front/node_modules/nft.storage/src'

我使用npm安装了这个包,然后在项目中导入它,如下所示:

import { NFTStorage, File } from 'nft.storage'
import { pack } from 'ipfs-car/pack';
const apiKey = 'MY_API_KEY'
const client = new NFTStorage({ token: apiKey })

这对我有效,而不是使用

import { NFTStorage, File } from 'nft.storage';

使用

import { NFTStorage, File } from 'nft.storage/dist/bundle.esm.min.js';

参考编号:https://github.com/nftstorage/nft.storage/issues/876

最新更新