-
Notifications
You must be signed in to change notification settings - Fork 105
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
ERR_PACKAGE_PATH_NOT_EXPORTED: No "exports" main defined in helia/package.json #190
Comments
+1 |
I'm having same issue |
Helia is an ESM-only module. You cannot use 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. Chances are, ts-node is compiling to CJS in the background. You must configure typescript to output ESM. |
I’m using import, on a nestjs project. |
@tomachianura can you provide your source code or a reproducible example so we can dive deeper? |
For others here, please check out #216 (comment) and let us know if you continue to have issues, but confirm your build tool supports ESM. |
There's also a helia-ts-node example to show how to get it working, it needs a bit of extra config. |
we work with CommonJS, and we can't change this. |
Yes, please see the helia-cjs example for how to use Helia from a CommonJS project. |
even when looking at can you kindly provide any solution to that please? |
I'm guessing that you have a NextJS project, you've set I'm guessing that you've done something like: const { createHelia } = await import('helia'); and you've checked your output folder and seen it being transpiled to: const { createHelia } = await Promise.resolve().then(() => require('helia')); The solution here appears to be to change If this does not solve your problem then you are going to have to provide a link to your source code or a reproducible example for us to assist further, because all this guess work has a high cost in time spent and a low probability of success. |
it's not Next, it's Nest :) Clearly, your suggestions described in the helia-nestjs doesn't work, cause changing CommonJS for something else is NOT a solution, considering it'll break a whole project. Looking forward to have a valid solution, thanks again! wish you all a great weekend ahead! |
Yes please. We can provide much better help with reproducible code. Thanks! |
TBH I'm not sure if that's going to add much value since there an example available of how to configure NestJS to work with Helia, so we know the default settings for NestJS are to build CJS, and we know the config changes needed to make it build ESM, but you can't apply them because it "breaks the entire project". The root of the issue here is that To prevent his happening you have to Your TypeScript settings are (I think, please confirm) transpiling This is not a problem specific to Helia, you'll have this problem with any module written in ESM that use an exports map. I suggest fixing your project so it can work with ES modules. This might be as simple as adding If you won't do this then the only other thing you can do is try to defeat the transpilation of const { createHelia } = await eval('import("helia")') |
totally correct! I'll do my best to make the entire thing ESM, but this will require a huge effort and long time to sync all the team and the deploys of the project, so for now your solution works just great! thanks a lot @achingbrain! |
'Helia is an ESM-only module. You cannot use require to load it, you must use import." |
There is nothing stopping you from using Helia in Electron - please see the Running Helia in Electron example for how to get started. |
OK That's encouraging! Thank you for the link. |
Error
main.ts
dependencies:
"helia": "^1.3.8"
"@helia/strings": "^1.0.0",
When I just simply run the above code with
ts-node main.ts
The text was updated successfully, but these errors were encountered: