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]: No "exports" main defined in package.json #4138

Closed Schwartz10 closed 2 years ago

Schwartz10 commented 2 years ago

Severity:

High - The main functionality of the application does not work, API breakage, repo format breakage, etc.

Description:

I've been trying to get a simple typescript nodejs project to import dependencies from ipfs on npm, but always results in

[ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json

This sounds related to https://github.com/ipfs/js-ipfs/issues/4135 and https://discuss.ipfs.io/t/ts-ipfs-core-example-v0-15-0-causes-error-opposed-to-v0-14-0/14460

Steps to reproduce the error:

Clone this repo, npm i, and npm start

achingbrain commented 2 years ago

ipfs@0.63.x is ESM-only, which means you can't use require to load it, you have to use import. Please see the upgrade guide.

Note if you're using TypeScript you'll need to specify "module": "ES2020" and "target": "ES2015" in your tsconfig.json file.

rafinskipg commented 1 year ago

@achingbrain I'm really stupid to understand how to solve this. Can you provide some examples on how to use your package now with other packages when bundling? version 56.0.2 seems to work well with everthing

woodjs commented 1 year ago
async function loadIpfs() {

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

    return ipfs;
}
andarocks commented 1 year ago

I am still getting the same error while trying the above code. I am using ipfs-http-client and using NestJs. Can anyone please help me out?

kuzdogan commented 1 year ago

Use a pre-ESM version of the ipfs-http-gateway. This is difficult to find but apparently with v0.10.0 it became ESM only.

npm i -d --save-exact ipfs-http-gateway@v0.9   
ekhishigee commented 1 year ago

@kuzdogan I am still getting the same error. I am using ipfs-http-client@v60 in NestJS. I would like to know how to solve that problem.

ikaz-jem commented 1 year ago

[ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in package.json

use type:module and use import {create} instead of requiring http client it , it worked