js-ipfs-utils icon indicating copy to clipboard operation
js-ipfs-utils copied to clipboard

NodeJS and Electron conflict

Open xmaysonnave opened this issue 4 years ago • 4 comments

Env:

  • Debian Buster
  • latest nvm
  • latest yarn
  • node v15
  • latest ipfs-core

I try to use js-ipfs while testing with NodeJS. As a dependency of ipfs-core, ipfs-utils is installed (dev dependency) https://github.com/ipfs/js-ipfs-utils/blob/master/src/http/fetch.js

This code check whether or not XMLHttpRequest is available in node and redirect to fetch.browser when available. However my environment is node and ipfs-utils crashes as fetch.browser requires the global browser fetch. I could suggest to enhance the initial statement with the following to redirect to fetch.node

if (typeof XMLHttpRequest === 'function' && typeof fetch === 'function') {
  module.exports = require('./fetch.browser')

Thanks

xmaysonnave avatar Dec 03 '20 05:12 xmaysonnave

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.

welcome[bot] avatar Dec 03 '20 05:12 welcome[bot]

jest is responsible of this behaviour. migrated jest tests to chai, mocha and sinon. no more issues

xmaysonnave avatar Dec 12 '20 06:12 xmaysonnave

Thanks for following up. I think it'd still be a good idea to expand the feature detection as suggested and issues with Jest do come up from time to time.

achingbrain avatar Dec 14 '20 07:12 achingbrain

Thanks for your feedback. ipfs-provider is using Jest. This is the reason I started to use it a while back. Probably an input in a knowledge base could be interesting as known issues. I enjoy spawning javascript Ipfs server in my tests, great feature. Feel free to close this issue.

xmaysonnave avatar Dec 14 '20 09:12 xmaysonnave