ipfs / js-ipfs

IPFS implementation in JavaScript
https://js.ipfs.tech
Other
7.44k stars 1.25k forks source link

ERR_PACKAGE_PATH_NOT_EXPORTED for ipfs-core #4125

Closed ibaraki-douji closed 2 years ago

ibaraki-douji commented 2 years ago

Severity:

Medium - A non-essential functionality does not work, performance issues, etc.

Description:

So i just setup the new ipfs project and when i was trying to start the program i got an error.

root@ae47c7682c9d:~/code# node ./lib/main.js
node:internal/modules/cjs/loader:488
      throw e;
      ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /root/code/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._load (node:internal/modules/cjs/loader:778:27)
    at Module.require (node:internal/modules/cjs/loader:1005:19)
    at require (node:internal/modules/cjs/helpers:102:18)
    at Object.<anonymous> (/root/code/lib/main.js:4:21) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
welcome[bot] commented 2 years ago

Thank you for submitting your first issue to this repository! A maintainer will be here shortly to triage and review. In the meantime, please double-check that you have provided all the necessary information to make this process easy! Any information that can help save additional round trips is useful! We currently aim to give initial feedback within two business days. If this does not happen, feel free to leave a comment. Please keep an eye on how this issue will be labeled, as labels give an overview of priorities, assignments and additional actions requested by the maintainers:

Finally, remember to use https://discuss.ipfs.io if you just need general support.

wouldgo commented 2 years ago

I resolved this loading the module via

const IPFS = await import('ipfs-core')

instead of requiring it.

ibaraki-douji commented 2 years ago

Ok so with js it works fine but with typescript it keeps crashing ... I will try to find for typescript. Thanks man

ibaraki-douji commented 2 years ago

For typescript users : To have this error removed you need to change compilerOptions.module to ESNext in the tsconfig.json

If you keep CommonJS it will transpile to a require() with a promise and it will give the error.

MiqueiasGFernandes commented 1 year ago

I resolved this loading the module via

const IPFS = await import('ipfs-core')

instead of requiring it.

@wouldgo After lost so many time searching a solution between it closed issues without reason, Your reply solved my problem, thanks for this!