ipfs / js-ipfs

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

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /www/orbitdb/node_modules/ipfs-http-client/package.json #4139

Closed rrubio closed 2 years ago

rrubio commented 2 years ago

IPFS Version -

NodeJS Version -

NPM Version -

OS -

Error occurs when i run my script like so "node client.js" -

` const IpfsClient = require('ipfs-http-client') const OrbitDB = require('orbit-db')

const ipfs = IpfsClient('localhost', '5001')

(async () => {

const orbitdb = await OrbitDB.createInstance(ipfs)

const db = await orbitdb.log('hello-world')

})() `

I have tried adding the following to "node_modules -> ipfs-http-client -> package.json" with no luck -

"exports": { ".": { "import": "./src/index.js" }, "./client": "./client.js"

Please note - i get the exact same error when using "ipfs".

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.

achingbrain commented 2 years ago

The latest ipfs-http-client is ESM only. This means you cannot use require to load the module, you must use import.

Please see the upgrade guide.

ffarall commented 2 years ago

Hey! I am using import { create } from "ipfs-http-client"; in my project, and I still get this error, any idea why that could be?

It seems to be due to the fact that I'm using it in a HardHat task, and that is not an ESM, even though I am using import for everything.

nanoTitan commented 2 years ago

I'm seeing the same thing. I'm using es6 import and getting that same error: import { create } from 'ipfs-http-client';

No "exports" main defined in ...\node_modules\ipfs-http-client\package.json

achingbrain commented 2 years ago

If you're doing something like using typescript with import in your .ts files and still seeing No "exports" main defined in, chances are your tsc config is set to output CJS. It needs to be ESM - set this using the "module" key in tsconfig.json - it should be "es2020" at least.

nanoTitan commented 2 years ago

Yes, that is the problem I figured out just recently. I'm using NestJS which doesn't support ESM modules right now. Also, doing dynamic imports with const { create } = await import('ipfs-http-client') isn't working for me either.

krakovia-evm commented 2 years ago

Hey! I am using import { create } from "ipfs-http-client"; in my project, and I still get this error, any idea why that could be?

It seems to be due to the fact that I'm using it in a HardHat task, and that is not an ESM, even though I am using import for everything.

had same problem with HH right now, but i used that module in the past. Resolved with pnpm i ipfs-http-client@56.0.2

zeyugan commented 2 years ago

pnpm i ipfs-http-client@56.0.2

This solved our problem when using nestJs, thanks!

kc97ble commented 2 years ago

Hey! I am using import { create } from "ipfs-http-client"; in my project, and I still get this error, any idea why that could be? It seems to be due to the fact that I'm using it in a HardHat task, and that is not an ESM, even though I am using import for everything.

had same problem with HH right now, but i used that module in the past. Resolved with pnpm i ipfs-http-client@56.0.2

Downgrading to version 56.x.x works for me.

rahulrumalla commented 1 year ago

Same here. Downgrading to ipfs-http-client@56.0.2 worked for me. Will there be a fix for this in the higher versions?

bhflm commented 1 year ago

Confirm, was having this problem until I did downgrade to 56.0.2 and it worked :) 👍🏼

josh-richardson commented 1 year ago

I'm also hitting this when using ipfs-http-client in Nest, with typescript and only importing using import { create } from 'ipfs-http-client';.

hubsmoke commented 1 year ago

Please see this comment https://github.com/ipfs/js-ipfs/issues/4180#issuecomment-1319951128

BigBen3918 commented 1 year ago

@KKRAKOVIA Thank you. Issue solved. Great!

francesco-gaglione commented 1 year ago

Downgrading to v56.0.2 and with this code:

let ipfs: IPFSHTTPClient = create({
                host: "ipfs.infura.io",
                port: 5001,
                protocol: "https",
                headers: {
                    authorization: this.auth
                }
            });

            ipfs.add("test").then((res)=>{
                resolve(res.cid.toString());
            })

I have this error:

TypeError: RequestInit: duplex option is required when sending a body.

It seem to be a node fetch error, how to solve?

Raman-Raje commented 1 year ago

@francesco-gaglione I am also getting the same error... Were you able to resolve it....?

rafinskipg commented 1 year ago

I'm getting the same error

mime29 commented 1 year ago

Same here and the only way I found to fix it was to modify the source ->

image
phungson185 commented 1 year ago

Hey! I am using import { create } from "ipfs-http-client"; in my project, and I still get this error, any idea why that could be? It seems to be due to the fact that I'm using it in a HardHat task, and that is not an ESM, even though I am using import for everything.

had same problem with HH right now, but i used that module in the past. Resolved with pnpm i ipfs-http-client@56.0.2

Resolved my problem. Tks !!!