0

I wrote a native module in c++ using the v8.h headers and I want to import it in my electron app.

The module works fine. I compile it in it's own folder, then I copy-paste the .node into this boilerplate https://github.com/szwacz/electron-boilerplate and I require it using the bindings package.

I would like to use this https://github.com/electron-userland/electron-webpack-quick-start as a starting point to build my electron application. Mainly for two reasons: it is the recommended way and it promises to package your app for macos, linux and windows. I copied the folder containing the source code inside the root folder of the project, I added the bindings.gyp file and "nodeGypRebuild": "true", to the package.json in the root folder. The module is compiled with yarn install but if I try to import it import {Module} from 'MyModule' in src/main/index.js and run yarn dev the output is

Module not found: Error: Can't resolve 'MyModule' in '/Users/BiA/Src/WebPack/src/main'

While googling the problem I landed here https://github.com/chentsulin/electron-react-boilerplate/wiki/Module-Structure----Two-package.json-Structure and now I am even more confused, since there is no app/ folder in electron-webpack-quick-start

Can someone help me finding a way to exit from this dead end? Does it exist a documentation that covers this case? Even a working example, like an open source project where I can lear to do this would help.

edit: to better understand the problem I created a simple git repository: https://github.com/BiancoA/electron-webpack-quick-start-nm

BiA
  • 364
  • 2
  • 6
  • 23
  • Why do you use two package.json? In `electron-webpack-quick-start` you should put your files in the `src` folder – kontrollanten Oct 25 '17 at 16:29
  • @kontrollanten thanks for the comment. Do you mean that I should also put the code of my module? – BiA Oct 25 '17 at 18:25
  • Hard to say. Do you have a file called MyModule in `/Users/BiA/Src/WebPack/src/main`? – kontrollanten Oct 25 '17 at 19:52
  • I can copy (binding.gyp allows you to do that) the MyModule.node file into `/Users/BiA/Src/WebPack/src/main`, but this does not solve the problem – BiA Oct 25 '17 at 20:01
  • Okey. It would be helpful if you can show some code showing how you're importing and trying to use the module – kontrollanten Oct 25 '17 at 20:03
  • ok, tomorrow I will try to add a minimal working example – BiA Oct 25 '17 at 20:07
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/157584/discussion-between-bia-and-kontrollanten). – BiA Oct 26 '17 at 15:26

1 Answers1

1

I found a solution to the problem using yarn link: https://yarnpkg.com/lang/en/docs/cli/link/

here I saved the working project: https://github.com/BiancoA/electron-webpack-quick-start-nm

If there are other possible ways, I'll be happy to learn them

BiA
  • 364
  • 2
  • 6
  • 23