Home > front end >  Node Run script from IDE Fails No "exports" main defined
Node Run script from IDE Fails No "exports" main defined

Time:11-05

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:

  1. Changing my version of node
  2. Reinstalling the packages
  3. Using yarn instead

CodePudding user response:

This is because there is no main in that package's package.json (https://github.com/ipfs/js-ipfs/blob/master/packages/ipfs-http-client/package.json). Per this note in the changelog, the package is meant to be used with ESM, but that also wouldn't fix your problem because there's no export called ipfsClient; you need import { create } from 'ipfs-http-client'.

Edit: as noted in your comment, downgrading to a version from before the package switched to ESM also works. Details in the comment.

  • Related