Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

ERR_PACKAGE_PATH_NOT_EXPORTED #4127

Closed
ki4jgt opened this issue Jun 9, 2022 · 5 comments
Closed

ERR_PACKAGE_PATH_NOT_EXPORTED #4127

ki4jgt opened this issue Jun 9, 2022 · 5 comments
Labels
need/triage Needs initial labeling and prioritization

Comments

@ki4jgt
Copy link

ki4jgt commented Jun 9, 2022

  • Version:
    0.63.2

  • Platform:
    Windows 11, 64-bit

  • Subsystem:

Severity:

Critical

Description:

I've been working on a project for months. Updated IPFS to the latest version, and now when I try to require it, I get this error.

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in C:\Users\marye\onedrive\desktop\athenae 
server\node_modules\ipfs\package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:440:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:664:7)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:999:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (C:\Users\marye\onedrive\desktop\athenae server\index.js:4:14) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

Steps to reproduce the error:

const ipfs = require("ipfs")
const node = ipfs.create()
@ki4jgt ki4jgt added the need/triage Needs initial labeling and prioritization label Jun 9, 2022
@FatNerdPeng
Copy link

我在使用ipfs-core这个库时遇到了同样的问题,我的解决办法是降低库的版本

@eltorio
Copy link

eltorio commented Jun 10, 2022

Same error here,
(node 16.15.1 LTS)

test.ts

import {create} from 'ipfs-core'

create().then((ipfs) => {
  ipfs.add('Hello world').then((cid) => {
    console.info(cid)
  })
})

package.json

{
  "scripts": {
    "test": "ts-node test.ts"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/node": "^17.0.41",
    "@types/orbit-db": "github:orbitdb/orbit-db-types",
    "ipfs-core-types": "^0.11.0",
    "ts-node": "^10.8.1",
    "tsconfig-paths": "^4.0.0",
    "tsup": "^6.1.0",
    "typescript": "^4.7.3",
    "npm-check-updates":"^13.1.2"
  },
  "dependencies": {
    "cors": "^2.8.5",
    "express": "^4.18.1",
    "orbit-db": "^0.28.6",
    "ipfs-core":"^0.15.1"
  },
  "engines": {
    "node": "16.x"
  }
}

tsconfig.json

{
    "compilerOptions": {
      "baseUrl": ".",
      "target": "es2017",
      "module": "CommonJS",
      "lib": [
        "esnext"
      ],
      "moduleResolution": "node",
      "esModuleInterop": true,
      "strict": true,
      "noEmit": true,
      "strictNullChecks": true,
      "resolveJsonModule": true,
      "skipDefaultLibCheck": true,
      "emitDecoratorMetadata": true,
      "experimentalDecorators": true,
      "outDir": "./dist",
      "strictPropertyInitialization": false,
      "paths": {
        "~/*": [
          "./src/*"
        ],
        "~~/*": [
          "./*"
        ]
      }
    },
    "ts-node": {
      "require": ["tsconfig-paths/register"]
    }
  }
orbitdb-server % npm run test

> test
> ts-node test.ts

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /Users/user/Development/orbitdb-server/node_modules/ipfs-core/package.json
    at new NodeError (node:internal/errors:372:5)
    at throwExportsNotFound (node:internal/modules/esm/resolve:472:9)
    at packageExportsResolve (node:internal/modules/esm/resolve:693:7)
    at resolveExports (node:internal/modules/cjs/loader:482:36)
    at Function.Module._findPath (node:internal/modules/cjs/loader:522:31)
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:919:27)
    at Function.Module._resolveFilename.sharedData.moduleResolveFilenameHook.installedValue (/Users/user/Development/orbitdb-server/node_modules/@cspotcode/source-map-support/source-map-support.js:811:30)
    at Function.Module._resolveFilename (/Users/user/Development/orbitdb-server/node_modules/tsconfig-paths/src/register.ts:115:36)
    at Function.Module._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}

@eltorio
Copy link

eltorio commented Jun 10, 2022

my workaround is to modify ipfs-core/package.json

  "exports": {
    ".": "./src/index.js",
    "./config/profiles": {
      "import": "./src/components/config/profiles.js"
    }
  },

@BigLep
Copy link
Contributor

BigLep commented Jun 10, 2022

@ki4jgt : You'll need to update to use ESM. See https://github.com/ipfs/js-ipfs/blob/master/docs/upgrading/v0.62-v0.63.md#esm

@eltorio : Please change your typescript configuration to produce ESM not CJS.

@BigLep BigLep closed this as completed Jun 10, 2022
@ki4jgt
Copy link
Author

ki4jgt commented Jun 12, 2022

@BigLep, I'm a little out of touch with that process. Can you show me how? I watched a video on YouTube, on importing, but with the node_modules folder, where am I pointing exactly?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
Development

No branches or pull requests

4 participants