js-ipfs
js-ipfs copied to clipboard
Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'dns' imported
- 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:
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.
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.
@lakshyabatman i'm also getting the same error, have you got any solution for it ?
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 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 I don't know alot about ipfs, I think you should open a new issue for that.
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.
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
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
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.