Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

error importing ipfs-core from TypeScript "Cannot find namespace 'fs'." #4080

Closed
gobengo opened this issue Apr 9, 2022 · 5 comments · Fixed by ipfs/js-ipfs-utils#178 or #4086
Closed
Labels
need/triage Needs initial labeling and prioritization

Comments

@gobengo
Copy link
Contributor

gobengo commented Apr 9, 2022

  • Version: 0.14.2
  • Platform: Darwin MacBook-Pro.local 21.3.0 Darwin Kernel Version 21.3.0: Wed Jan 5 21:37:58 PST 2022; root:xnu-8019.80.24~20/RELEASE_ARM64_T8101 arm64

  • Subsystem:

  • ipfs-core package

    • it's even possible that this is a quirk of how npm publish happens, since the error references node_modules/ipfs-utils/dist/src/files/glob-source.d.ts

Severity: High (library not usable in this context)

Description:

Note: this issue is similar to #4029 , but a different ts error so not the same

Steps to reproduce the error:

  • start a new typescript project
  • import * as IPFS from 'ipfs-core'
  • try to tsc build
  • see error
bengo@MacBook-Pro ~/dev/ipld-experiments/ipld-web3-storage ⚡  npm run build                                         

> ipld-web3-storage@1.0.0 build
> tsc

node_modules/ipfs-utils/dist/src/files/glob-source.d.ts:10:14 - error TS2503: Cannot find namespace 'fs'.

10     content: fs.ReadStream | undefined;
                ~~


Found 1 error in node_modules/ipfs-utils/dist/src/files/glob-source.d.ts:10

I tried clonging js-ipfs repo myself to npm link and find a fix, but npm install on my m1 mac fails because npm ERR! response status 404 Not Found on https://node-webrtc.s3.amazonaws.com/wrtc/v0.4.7/Release/darwin-arm64.tar.gz which is node-webrtc/node-webrtc#680

@gobengo gobengo added the need/triage Needs initial labeling and prioritization label Apr 9, 2022
@welcome
Copy link

welcome bot commented Apr 9, 2022

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:

  • "Priority" labels will show how urgent this is for the team.
  • "Status" labels will show if this is ready to be worked on, blocked, or in progress.
  • "Need" labels will indicate if additional input or analysis is required.

Finally, remember to use https://discuss.ipfs.io if you just need general support.

@gobengo
Copy link
Contributor Author

gobengo commented Apr 11, 2022

I was able to recreate this issue only against ipfs-utils, not ipfs-core. So I will open an issue/PR there.

The good news is I think I also have a patch for ipfs-utils that will fix it (based on npm link testing)

@callezenwaka
Copy link

Hi,
Any solution to this yet? Ran into same issue.

achingbrain pushed a commit to ipfs/js-ipfs-utils that referenced this issue Apr 19, 2022
Motivation:
* Fix ipfs/js-ipfs#4080
* tl;dr
  * fix `import globSourceImport from 'ipfs-utils/src/files/glob-source.js'` from typescript
  * fix importing ipfs-core from typescript

Context:
* microsoft/TypeScript#23857

Strategy
* Use jsdoc `@return` instead of `@yields` because tsc doesn't understand that `@yields` implies a `@return` type

Test Case
* gobengo/ipfs-core-esm-test#3
* I tested locally with `npm link` and this seemed to fix it
@jamesrwaugh
Copy link

jamesrwaugh commented Apr 20, 2022

@callezenwaka For now, adding "skipLibCheck": true to tsconfig compilerOptions worked for me.
As per #4029 (comment)

@gobengo gobengo reopened this Apr 20, 2022
@gobengo
Copy link
Contributor Author

gobengo commented Apr 20, 2022

reopening to track ipfs-core upgrading to the fixed ipfs-utils@9.0.6 (if needed)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
need/triage Needs initial labeling and prioritization
Projects
None yet
3 participants