Why does npm call ipfs-core a native dependency?

Hello everyone,

In the process of attempting to create a template of electron-react-boilerplate with ipfs-core (currently a work in progress), I run into a curious problem.
If you clone the above repo, make sure that ipfs-core is NOT listed as a dependency (nor a devDependency) in package.json, then run:

npm install
npm install ipfs-core 
npm start

then I see the app working as intended. (It’s a one page app that simply displays peerID and version info for your javascript ipfs node.) After the installation of ipfs-core, in package.json, I see, as expected:

"ipfs-core": "^0.17.0",

However, if I manually place ipfs-core into package.json as a dependency prior to the initial installation step, then when I try to install, I get the error:

 Webpack does not work with native dependencies.
ipfs-core is a native dependency and should be installed inside of the "./release/app" folder.
 First, uninstall the packages from "./package.json":
npm uninstall your-package
 Then, instead of installing the package to the root "./package.json":
npm install your-package
 Install the package to "./release/app/package.json"
cd ./release/app && npm install your-package
 Read more about native dependencies at:
https://electron-react-boilerplate.js.org/docs/adding-dependencies/#module-structure

This is strange because ipfs-core is written in javascript, and by my understanding, native dependencies are the ones that are NOT written in javascript. So is npm miscategorizing ipfs-core for some reason?

I’ve tried doing the things your’re supposed to do in electron-react-boilerplate for native dependencies:

cd release/app
npm install ipfs-core 
npm run postinstall 
cd ../..
npm start

but I haven’t gotten that to work in the app.

I’m a novice when it comes to electron and native dependencies, so it’s very possible I’m misunderstanding something.

Thank you in advance for any insights you may have!

1 Like

When you run npm install, npm executes the postinstall script defined in your package.json. You’ll notice this script gets called, which is probably the culprit: electron-react-boilerplate-ipfs-core/check-native-dep.js at main · wds4/electron-react-boilerplate-ipfs-core · GitHub

Installing a single dependency does not execute the postinstall script (I don’t believe)

1 Like

I hadn’t realized postinstall was executed with npm install. But you’re definitely right about that script – I can see that’s where the error messages are coming from. I’ll dig into it to see how/why it’s labelling it as native. If I find anything interesting I’ll post it here. Thank you!

I learned two things that are relevant.

First: there is a dependency called “classic-level” which is 1) recognized by the above script as a native module and 2) in the dependency tree for ipfs-core. This must be why ipfs-core triggers the above script to throw an error.

Second: If I install ipfs-core as a devDependency (NOT a dependency) in the root package.json, then ipfs-core does NOT get placed as a dependency in the app package.json, and the above script no longer throws the error. This makes sense to me. And the app works fine in dev mode. This also makes sense to me.

Here’s what I don’t understand: Despite the fact that ipfs-core is not in the app package.json, the packaged app still seems to work just fine, as if ipfs-core were in the packaged app – but it’s not, since it’s not in the app package.json, right?? (Gotta hate it when your app works and you don’t know why, right? lol)

There must be something I am not understanding about the electron-builder two package structure. Can anyone can tell me what I am missing? Once again, thank you in advance!