Closed rawatnaresh closed 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.
I also have this issue.
I have a basic implementation:
import { create } from "ipfs-http-client";
const client = create();
async function addFiles(arrayOfFiles) {
const result = [];
for await (const resultPart of client.addAll(arrayOfFiles)) {
result.push(resultPart);
}
}
@king-Alex-d-great you would have to change your firebase-functions to use ES modules
for this package to work. By default firebase functions use commonjs
. In order to do that add "type": "module"
in your package.json file.
const { create } = require('ipfs-http-client')
const client = create();
where the project type is nothing or commonjs (nothing defaults to commonjs) gives the same error.
Currently that means i must convert to a "type":"module"
or downgrade to the previous release where this was working just fine.
I'm curious why the main
attribute from package.json was removed, this would serve as a fallback for cjs imports. Not everyone can easily migrate their project to use "type":"module"
Downgrading to ipfs-http-client
56.0.0 fixed this for me.
Having this same issue.
Not sure why nobody's come along to let this thread know, but apparently you can use dynamic imports in CJS apps still: https://github.com/ipfs/js-ipfs/blob/master/docs/upgrading/v0.62-v0.63.md
Not sure why nobody's come along to let this thread know, but apparently you can use dynamic imports in CJS apps still: https://github.com/ipfs/js-ipfs/blob/master/docs/upgrading/v0.62-v0.63.md
This did not work for me, not sure if it requires additional tsconfig properties, but I get the same ERR_PACKAGE_PATH_NOT_EXPORTED
thrown from the dynamic import. I'm using esModuleInterop: true
and running via ts-node, which may be relevant.
This did not work for me, not sure if it requires additional tsconfig properties, but I get the same
ERR_PACKAGE_PATH_NOT_EXPORTED
thrown from the dynamic import. I'm usingesModuleInterop: true
and running via ts-node, which may be relevant.
Not working for me either.
Your tsconfig is set to output CJS - it needs to output ESM instead.
Add "type": "module"
to your package.json
, and in tsconfig.json
change "module"
to "ES2020"
and add "moduleResolution": "node"
.
Your tsconfig is set to output CJS - it needs to output ESM instead.
Add
"type": "module"
to yourpackage.json
, and intsconfig.json
change"module"
to"ES2020"
and add"moduleResolution": "node"
.
That doesn't fix the issue when your entire codebase is CJS you can't just switch to module without refactoring everything, including other third party packages that simply won't include properly as a module.
Also, in my case I'm not using Typescript
@CorpulentBrony sorry it wasn't clear - I was replying to the OP, who has supplied a repro case that needs an update to it's tsconfig.json
for it to work.
If you have a repro case I can take a look, but as you've found if you are using CJS and cannot upgrade, you need to use a dynamic import to load ESM modules.
@achingbrain As @CorpulentBrony said it does not make sense to me as well because I have tested ESM config breaks everything.
If you have a repro case I can take a look, but https://github.com/ipfs/js-ipfs/issues/4180#issuecomment-1250182601 if you are using CJS and cannot upgrade, you need to use a dynamic import to load ESM modules.
I could not understand why and all context of this. I just wonder if there is no possibility to go back to CJS, the ultimate solution is just to keep 56.x at the moment? (FYI, I am using typescript)
I figured out a magical incantation of tsconfig.json and package.json that allows us to use ipfs-http-api via typescript import
Link to minimum good configuration example repo: https://github.com/hubsmoke/ipfs-typescript-starter (run npm run start:dev
to execute)
@hubsmoke this almost works but the npm run build
command in your repo fails. To get it to work set target and module to "es2020"
and remove "lib"
:
{
"compilerOptions": {
"target": "es2020",
"module": "es2020",
"moduleResolution": "node",
"allowJs": true,
"outDir": "build",
"rootDir": "src",
"strict": true,
"noImplicitAny": true,
"esModuleInterop": true,
},
"ts-node": {
"esm": true
},
}
There's more info in the upgrade guide
Awesome thanks for catching that. Here's the diff following your suggestions, which did improve the situation: https://github.com/hubsmoke/ipfs-typescript-starter/commit/58837da953946bd3b513fb90476b3cb4a5de4c33
However it still results in:
> ipfs-experiment@1.0.0 build
> rimraf ./build && tsc
node_modules/ipfs-utils/dist/src/files/glob-source.d.ts:7:20 - error TS2307: Cannot find module 'ipfs-unixfs/types/src/types' or its corresponding type declarations.
7 mtime?: import("ipfs-unixfs/types/src/types").MtimeLike | undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
node_modules/ipfs-utils/dist/src/files/glob-source.d.ts:12:19 - error TS2307: Cannot find module 'ipfs-unixfs/types/src/types' or its corresponding type declarations.
12 mtime: import("ipfs-unixfs/types/src/types").MtimeLike | undefined;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Found 2 errors in the same file, starting at: node_modules/ipfs-utils/dist/src/files/glob-source.d.ts:7
I will need to tweak this to fix this issue -- I've run into it in the past just forgot what it needs. Took a look at the upgrade guide, but unclear what I would need to do to fix the above, lmk if you have any ideas. Thanks for your help! IMO would be great to have a community working template to get folks going on IPFS quickly.
Delete your lock file and reinstall
@achingbrain awesome! Had to nuke my node_modules as well. Thanks for your help & attention 💯
Version: 57.0.3
Platform: Darwin Nareshs-MacBook-Air.local 20.5.0 Darwin Kernel Version 20.5.0: Sat May 8 05:10:33 PDT 2021; root:xnu-7195.121.3~9/RELEASE_X86_64 x86_64
Subsystem:
Severity:
High
Description:
I'm trying to use
ipfs-http-client
with Firebase cloud functions but I'm getting an error while importing it.Steps to reproduce the error:
ipfs-http-client