js-ipfs icon indicating copy to clipboard operation
js-ipfs copied to clipboard

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dns' imported

Open lakshyabatman opened this issue 3 years ago • 8 comments

  • Version: "^0.15.4"
  • Platform: macos
  • Subsystem:

Severity:

Description:

import * as IPFS from 'ipfs-core';

const ipfs = IPFS.create();

(async () => { 
    const res = await ipfs.add("hello world")
    console.log(res);
})()

This is just I'm trying to achieve, but getting this weird error :/

Steps to reproduce the error:

lakshyabatman avatar Jul 07 '22 16:07 lakshyabatman

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:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

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

welcome[bot] avatar Jul 07 '22 16:07 welcome[bot]

And the error I got

node src/index.js
internal/process/esm_loader.js:74 internalBinding('errors').triggerUncaughtException( ^

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dns' imported from /Users/lakshya/Desktop/projects/week-4/ipfs-upload/node_modules/@multiformats/multiaddr/dist/src/resolvers/dns.js at new NodeError (internal/errors.js:322:7) at packageResolve (internal/modules/esm/resolve.js:732:9) at moduleResolve (internal/modules/esm/resolve.js:773:18) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:887:11) at Loader.resolve (internal/modules/esm/loader.js:89:40) at Loader.getModuleJob (internal/modules/esm/loader.js:242:28) at ModuleWrap. (internal/modules/esm/module_job.js:76:40) at link (internal/modules/esm/module_job.js:75:36) { code: 'ERR_MODULE_NOT_FOUND'

lakshyabatman avatar Jul 07 '22 18:07 lakshyabatman

@lakshyabatman i'm also getting the same error, have you got any solution for it ?

youngnishant avatar Jul 31 '22 15:07 youngnishant

I also got the same error on NodeJS v14 fixed by upgrading NodeJS to v15+ because ipfs is using multiformats package that is using dns/promises package https://github.com/multiformats/js-multiaddr/blob/master/src/resolvers/dns.ts#L1 and dns/promises works on NodeJS v15+ https://nodejs.org/api/dns.html#dns-promises-api

zakariamouhid avatar Aug 04 '22 01:08 zakariamouhid

@zakariamouhid thanks and when i tried to deploy it on heroku its giving error that not able to bind port, I've tried everything, can you guide me how can i use heroku hosted ipfs using url?

youngnishant avatar Aug 05 '22 07:08 youngnishant

@youngnishant I don't know alot about ipfs, I think you should open a new issue for that.

zakariamouhid avatar Aug 06 '22 19:08 zakariamouhid

I get the same error:

javaspeak@Johns-MacBook-Pro server % npm start dev

> [email protected] start 
/Users/javaspeak/workspace3/symbiont/permanent_node/server
> node server "dev"

 (node:19910) UnhandledPromiseRejectionWarning: Error 
 [ERR_MODULE_NOT_FOUND]: Cannot find package 'dns' imported from 

/Users/javaspeak/workspace3/symbiont/permanent_node/server/node_modules/@multiformats/multiaddr/dist/src/resolvers/dns.js at packageResolve (internal/modules/esm/resolve.js:650:9) at moduleResolve (internal/modules/esm/resolve.js:691:18) at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:805:11) at Loader.resolve (internal/modules/esm/loader.js:88:40) at Loader.getModuleJob (internal/modules/esm/loader.js:241:28) at ModuleWrap. (internal/modules/esm/module_job.js:72:40) at link (internal/modules/esm/module_job.js:71:36)

I am using ipfs in node. Imported it as follows:

const createIpfs = async () => {

    const { create } = await import('ipfs')

UPDATE: I am using nvm and get the error with:

    v14.17.3
    v15.0.0

I do not get the dns error with:

    v15.7.0

and above

javaspeak avatar Sep 17 '22 20:09 javaspeak

I also got the same error on NodeJS v14 fixed by upgrading NodeJS to v15+ because ipfs is using multiformats package that is using dns/promises package https://github.com/multiformats/js-multiaddr/blob/master/src/resolvers/dns.ts#L1 and dns/promises works on NodeJS v15+ https://nodejs.org/api/dns.html#dns-promises-api

I tried:

v15.0.0

and got the same error.

UPDATE: Did NOT get the dns error with:

v15.7.0

javaspeak avatar Sep 17 '22 20:09 javaspeak

Please update your version of node to a supported version - 16.x.x at the time of writing, this should resolve your issue as some people in this thread have found.

achingbrain avatar Sep 30 '22 14:09 achingbrain