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

ipfs-http-client doesn't work in the browser with Meteor #3557

Closed
yurtsiv opened this issue Feb 17, 2021 · 13 comments
Closed

ipfs-http-client doesn't work in the browser with Meteor #3557

yurtsiv opened this issue Feb 17, 2021 · 13 comments
Assignees
Labels
kind/support A question or request for support kind/wontfix-migration-available

Comments

@yurtsiv
Copy link

yurtsiv commented Feb 17, 2021

  • Version: 49.0.2

  • Platform:
    Linux hostname 5.10.15-1-MANJARO #1 SMP PREEMPT Wed Feb 10 10:42:47 UTC 2021 x86_64 GNU/Linux

Severity: High

Description:

I’m having troubles using the latest version of ipfs-http-client with Meteor on the client.
It fails with: Object prototype may only be an Object or null: undefined.
This error comes from graceful-fs package. The dependency flow is as following:

ipfs-http-client -> ipfs-utils -> fs-extra -> graceful-fs

The latest working version is 41.0.1.

Steps to reproduce the error:

I've created a minimal reproduction of the issue. All the steps to reproduce the error are provided in README. Let me know if you need more details.

Thanks!

@yurtsiv yurtsiv added the need/triage Needs initial labeling and prioritization label Feb 17, 2021
@welcome
Copy link

welcome bot commented Feb 17, 2021

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.

@achingbrain
Copy link
Member

That's interesting - it's probably trying to pull node-specific code into a browser bundle.

Can you configure Meteor to follow browser semantics for building the front end code?

@yurtsiv
Copy link
Author

yurtsiv commented Feb 17, 2021

@achingbrain Yes, that's the case.

The meteor build system is not as configurable as say webpack. They provide meteor-node-stubs which mocks some of the Node.js modules, but the fs is set to null. Altough the fs is not actually null, becuase it would crash with a different error, so there's some additional magic going on.

I'm wondering, how does it work with webpack. Does the code which contains references to fs gets shipped to the browser with some stub implementation of fs or it just gets stripped out?

@achingbrain
Copy link
Member

fs-extra is used by ipfs-utils in the src/files/glob-source.js file. Glob sources are only used when importing from a filesystem so shouldn't be used in the browser.

Webpack respects the browser field in package.json which for ipfs-http-client sets src/files/glob-source.js to false so it doesn't get pulled in to the bundle which would pull fs-extra in with it.

@achingbrain achingbrain added kind/support A question or request for support and removed need/triage Needs initial labeling and prioritization labels Feb 18, 2021
@yurtsiv
Copy link
Author

yurtsiv commented Feb 18, 2021

Ok, turns out Meteor does respect browser field but only for relative paths (meteor/meteor#6890 (comment), meteor/meteor#9311).

Wouldn't it be better to specify browser specific files for a particular package in the package itself, thus reducing coupling? In this case move the declaration to ipfs-utils itself (same here).

@achingbrain
Copy link
Member

achingbrain commented Feb 24, 2021

Wouldn't it be better to specify browser specific files for a particular package in the package itself, thus reducing coupling?

Yes - could you please open a PR to the affected modules to make this change?

It sounds like it would then also fix the issue with Meteor.

@yurtsiv
Copy link
Author

yurtsiv commented Feb 25, 2021

Sure. Will do this in a few days.

@yurtsiv
Copy link
Author

yurtsiv commented Mar 8, 2021

Maybe a few days more 😅 Really busy currently

@yurtsiv
Copy link
Author

yurtsiv commented Apr 9, 2021

@achingbrain Just wondering, why js-ipfs-utils is not a part of this repo?

@achingbrain
Copy link
Member

It was briefly but it’s used in too many places so needed it’s own release schedule.

@yurtsiv
Copy link
Author

yurtsiv commented Apr 27, 2021

Hi. Can you take a look at the following PRs, please: #3630, ipfs/js-ipfs-utils#121

achingbrain pushed a commit to ipfs/js-ipfs-utils that referenced this issue Apr 28, 2021
@yurtsiv
Copy link
Author

yurtsiv commented Jun 15, 2021

To continue the discussion on #3630, I don't have a solution for normalise-input, BUT I do think it makes sense to at least get rid of

{
   ...
   "browser": {
      ...
      "ipfs-utils/src/files/glob-source": false
      ...
    }
}

in every applicable package.json under js-ipfs/packages, since it's already handled in ipfs-utils (ipfs/js-ipfs-utils#121). No need to have it twice.

Please confirm that my reasoning is correct and I'll make a PR.

@whizzzkid
Copy link

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

Please feel to reopen with any comments before 2023-06-05. We will do a final pass on reopened issues afterward (see #4336).

@github-project-automation github-project-automation bot moved this from 🛑 Blocked to ✅ Done in js-ipfs deprecation May 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/support A question or request for support kind/wontfix-migration-available
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants