I'm trying to create a project which deploys nfts to ipfs automatically. I downloaded an existing project and I'm trying to extend the functionality
My packages.json
looks like so:
{
"name": "3_market_engine",
"main": "index.js",
"bin": "index.js",
"pkg": {
"assets": [
"layers/**/*",
"node_modules/**/*",
"src/**/*"
]
},
"scripts": {
"build": "node index.js",
"generate": "node index.js",
"generate_metadata": "node utils/generate_metadata.js",
},
"dependencies": {
"canvas": "^2.8.0",
"dotenv": "^16.0.3",
"gif-encoder-2": "^1.0.5",
"ipfs-http-client": "^59.0.0",
"sha1": "^1.1.1"
}
I can run the npm run generate_metadata
command just fine however whenever I try to add a require statement to const { ipfsClient } = require('ipfs-http-client');
to the file I get an error:
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\source\3_market_nft_engine\node_modules\ipfs-http-client\package.json at new NodeError (node:internal/errors:393:5) at throwExportsNotFound (node:internal/modules/esm/resolve:358:9) at packageExportsResolve (node:internal/modules/esm/resolve:612:7) at resolveExports (node:internal/modules/cjs/loader:529:36) at Module._findPath (node:internal/modules/cjs/loader:569:31) at Module._resolveFilename (node:internal/modules/cjs/loader:981:27) at Module._load (node:internal/modules/cjs/loader:841:27) at Module.require (node:internal/modules/cjs/loader:1061:19) at require (node:internal/modules/cjs/helpers:103:18) at Object. (C:\source\3_market_nft_engine\utils\generate_metadata.js:4:20) { code: 'ERR_PACKAGE_PATH_NOT_EXPORTED' }
I've tried:
- Changing my version of node
- Reinstalling the packages
- Using yarn instead
1条答案
按热度按时间yfwxisqw1#
这是因为在这个包的
package.json
(https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/package.json)中没有main
。根据changelog中的这个注解,这个包是要和ESM一起使用的,但是这也不能解决你的问题,因为没有名为ipfsClient
的导出;您需要import { create } from 'ipfs-http-client'
。编辑:正如你在评论中提到的,降级到一个版本之前的软件包切换到ESM也工作。详细信息在评论中。