0

I found a github project, running electron with Rust, which looks quite simple. However, I have problem to successfully build it.
https://github.com/asaladino/electron-rust

When I tried to build with "npm build", I failed.

The followings were what I got:


PS D:_src.git\electron-rust> npm install

ref-napi@1.4.1 install D:_src.git\electron-rust\node_modules\ref-napi
node-gyp rebuild


D:_src.git\electron-rust\node_modules\ref-napi>if not defined npm_config_node_gyp (node "C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
gyp ERR! configure error
gyp ERR! stack Error: Command failed: C:\ProgramData\Anaconda3\python.EXE -c import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack File "", line 1
gyp ERR! stack import sys; print "%s.%s.%s" % sys.version_info[:3];
gyp ERR! stack ^
gyp ERR! stack SyntaxError: invalid syntax
gyp ERR! stack
gyp ERR! stack at ChildProcess.exithandler (child_process.js:294:12)
gyp ERR! stack at ChildProcess.emit (events.js:189:13)
gyp ERR! stack at maybeClose (internal/child_process.js:970:16)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd D:_src.git\electron-rust\node_modules\ref-napi
gyp ERR! node -v v10.15.1
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN electron-rust@1.0.0 No repository field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! ref-napi@1.4.1 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the ref-napi@1.4.1 install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Chaokuo\AppData\Roaming\npm-cache_logs\2019-05-05T14_44_35_607Z-debug.log

I also tried "electron ." Then electron app showed up. However, it may not call Rust program. The developer mode console showed that cannot find module 'ffi-napi'.

  • That project is expecting Python 2.7, yet the system is trying to run node-gyp's building scripts with your Python 3 from Anaconda. You could either try to update that project's dependencies so as to rely on Python 3, or tell node-gyp to use Python 2. – E_net4 May 05 '19 at 15:14

1 Answers1

0

There could be a lengthy process to follow. Please make sure you followed all the instructions at: https://github.com/nodejs/node-gyp

Your OS looks like Windows, so try to follow the following steps:

npm install -g node-gyp
npm install --global --production windows-build-tools (could take some time)
npm config set python /path/to/executable/python2.7 (so that always use 2.7)
node-gyp configure 
node-gyp build

Then add/edit file binding.gyp same location as package.json as follows:

{
    "targets": [
    {
        "target_name": "binding",
        "sources": [ "src/binding.cc" ]
    }
    ]
}
Jean-François Fabre
  • 137,073
  • 23
  • 153
  • 219
Thomas Mao
  • 23
  • 2
  • 7