Closed gouravkhator 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.
Also note that I have tried following solutions from https://github.com/electron/electron/issues/27961 But no luck. It didn't resolve my error.
I think the IPFS team needs to edit their versions of electron-fetch
npm package, because this issue can be solved as suggested by this comment
Seems like electron-fetch uses node-gyp, and as node-gyp does not work in browsers, it was having issues.
That's why process.versions did not have electron property.
Thus, I realised that the package might work, when used in a server. So, I created a server and in that server (i.e., nodejs environment), the ipfs-core package works fine.
Kindly check on how to enable the node-gyp in browsers.
IPFS uses electron-fetch
only when it detects that it is running inside electron. (It uses is-electron
to do that.)
Else, it uses native fetch. This piece of code can be found here.
node-gyp
is a cross-platform command-line tool written in Node.js for compiling native addon modules for Node.js.
Since it interacts with machine and filesystem, using it in browser is not possible.
Lastly, Try some insights from Issue #4011
But why I was getting the issue then, is there some dependency, which is causing the electron environment to be set partially, without setting the process.versions.electron
property.
Please check my package.json
file and help me resolve this issue, if there is some dependency which causes the electron environment to be set, which indirectly causes ipfs-utils
to import electron-fetch
module.
Having this same issue when using ipfs-utils in browser
Looks like a duplicate of https://github.com/ipfs/js-ipfs/issues/4011 ?
Why was this issue closed?
process.versions.electron
is somehow definedprocess.versions.electron
js-ipfs
because the library depends on electron-fetch
Version Details
Version: Using ipfs-core npm package version "^0.13.0"
Platform: Output of
uname -a
:Linux pop-os 5.15.8-76051508-generic #202112141040~1639505278~20.04~0ede46a-Ubuntu SMP Fri Dec 17 19: x86_64 x86_64 x86_64 GNU/Linux
Browser tested on: Firefox 95.0.1 (64-bit).
The ipfs-core is needed in a preact application with preact version "^10.3.1"
Subsystem: Not sure
Severity: High
Description:
ipfs-utils/src/fetch.js
relies onelectron-fetch/lib/index.es.js
.So, it gives error as below, when I run
npx preact build
:Side Notes
I have been using ipfs-core npm package in my preact project.
Preact uses webpack to bundle the application. I have not modified the default webpack config, which comes pre-packed in with mentioned preact package.
Steps to reproduce the error:
My code
In the stacktrace mentioned above,
The
./utils/ipfs.util.ts
file is my code.Root cause
After tracing the files from the stacktrace, I found that, there is some issue in
../node_modules/electron-fetch/lib/index.es.js
file:Pasting some parts of
../node_modules/electron-fetch/lib/index.es.js
file, which causes the issue:As the process.versions.electron is not there, the electron variable is not set, which leads to the issue.
My package.json file
Output of
process.versions
when run from my project files:@IPFS Developers, I humbly request you to provide support on this issue. It is impacting my side project and delaying my work.