Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/ec2-user/helia/node_modules/helia/package.json #216

Closed
hebr3rt opened this issue Aug 5, 2023 · 15 comments

Comments

@hebr3rt
Copy link

hebr3rt commented Aug 5, 2023

I'm just trying to get the following code to run:

const { createHelia } = require('helia');
const { dagJson } = require('@helia/dag-json');

but it give the error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/ec2-user/helia/node_modules/helia/package.json

I am using nodeJS and express

@nhattan097
Copy link

I got the same issue too

@achingbrain
Copy link
Member

achingbrain commented Aug 6, 2023

Helia is an ESM-only module. You cannot use require to load it, you must use import.

If you cannot use ESM for your project, you can use the dynamic import function to import it - please see the helia-cjs example for more.

@nhattan097
Copy link

nhattan097 commented Aug 6, 2023

image

I use dynamic import like you said but still get this error.

@achingbrain
Copy link
Member

I’m not familiar with Nest. Can you share a link to your project or a repro repo please?

@nhattan097
Copy link

Sorry, that's all I can share for you.

@nhattan097
Copy link

But somehow it's work on Nextjs normal, but when public CID to network that not work like I hope (error uncaughtException: Error: PublishError.InsufficientPeers). So I move to Nestjs and surprise I get error like this issue.

@achingbrain
Copy link
Member

Looking at the default TypeScript settings created by nest new project-name, it will output CJS.

It also uses jest and ts-jest which also appear to transpile to CJS by default so you will need to configure them to output ESM or to allow dynamic imports.

@nhattan097
Copy link

nhattan097 commented Aug 7, 2023

image

This is my tsconfig

@nhattan097
Copy link

nhattan097 commented Aug 7, 2023

@achingbrain I think my issue have connect this issue

@nhattan097
Copy link

Looking at the default TypeScript settings created by nest new project-name, it will output CJS.

It also uses jest and ts-jest which also appear to transpile to CJS by default so you will need to configure them to output ESM or to allow dynamic imports.

hi @achingbrain helia not support CJS?

@achingbrain
Copy link
Member

Helia supports CJS, please see the helia-cjs example.

With the right config it also works with NestJS, see the helia-nestjs example.

I see from your config above you are using Jest - here is the helia-jest example and the helia-jest-typescript example.

All of these examples have one thing in common - they configure the tools being used to work with ESM so the correct method of loading modules occurs.

Please check your config. If you still cannot solve this with the above examples as a reference, please create a small repo with a reproduction I can run, otherwise I cannot help you any further.

@nhattan097
Copy link

nhattan097 commented Aug 8, 2023

Helia supports CJS, please see the helia-cjs example.

With the right config it also works with NestJS, see the helia-nestjs example.

I see from your config above you are using Jest - here is the helia-jest example and the helia-jest-typescript example.

All of these examples have one thing in common - they configure the tools being used to work with ESM so the correct method of loading modules occurs.

Please check your config. If you still cannot solve this with the above examples as a reference, please create a small repo with a reproduction I can run, otherwise I cannot help you any further.

Thank a lot for your help. I appreciated it. But still not work for me. I think the problem come from nx. Specific you can see issue from here: nrwl/nx#10296

@SgtPooki
Copy link
Member

I'm closing this as resolved because it seems like it's due to an issue with the nx system and ESM. Also of note, this is related to #190

@nhattan097
Copy link

yeah, but I wonder ask you: I see ipfs-http-client v56.0.3 support CJS, and I am using this version. But when I up to date the lastest version and I have the error like this issue. Why don't you continue support like ipfs-http-client v56.0.3 for Helia?

@StrawberryChocolateFudge

Still have this issue in 2024. I'm unable to use Helia inside a hardhat project, unlike js-ipfs which always just worked. tweaking the tsconfig.json is just breaking other things.

With the default hardhat scaffold's config, I get the no "exports" error for the Helia examples and I don't use CommonJS at all anywhere.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Development

No branches or pull requests

5 participants