Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use oracledb in an electron app #918

Closed
n-riesco opened this issue May 25, 2018 · 13 comments
Closed

How to use oracledb in an electron app #918

n-riesco opened this issue May 25, 2018 · 13 comments

Comments

@n-riesco
Copy link

n-riesco commented May 25, 2018

I'm opening this issue to describe two approaches for using oracledb v2.2 in an electron app:

  1. Using electron-rebuild

    The key for this approach to work is to:

    • ensure that nan v2.8+ is listed amongst the dev dependencies (otherwise, electron-rebuild will fail with nan-related errors)
    • and run electron-rebuild at the postinstall step.

    I've created the repo oracledb-electron-rebuild with a working example.

  2. Using electron-builder

    The key for this approach to work is to:

    • use the source package from github:
      npm install --save https://github.com/oracle/node-oracledb/releases/download/v2.2.0/oracledb-src-2.2.0.tgz
      
    • and run electron-builder install-app-deps at the postinstall step.

    See the repo oracledb-electron-builder for a working example.


The reason for using the source package from github (instead of the package distributed via npm) is that, unlike the package from github, the npm package runs node package/oracledbinstall.js at the install step.

The purpose of oracledbinstall.js is to download prebuilt binaries built against node. Unfortunately, this script is unaware of the npm environment variables used for building electron apps and prevents node-gyp rebuild from running when building oracledb against electron.


A suggestion: prebuild (a tool for creating prebuilt binaries) and prebuilt-install (for installing them) are both aware of electron.

@dmcghan
Copy link

dmcghan commented May 25, 2018

Good stuff, @n-riesco. Thanks!

@cjbj
Copy link
Member

cjbj commented May 25, 2018

This will be really helpful. Thanks for posting.

@cjbj cjbj closed this as completed Jul 15, 2018
@markddrake
Copy link

I cannot get this to work on Windows using the latest release of oracledb

C:\Development\oracledb>python -V
Python 2.7.15
C:\Development\oracledb>npm install --save-dev electron
...

  • electron@4.0.1
    updated 1 package and audited 1167 packages in 5.114s
    found 0 vulnerabilities
    C:\Development\oracledb>npm install --save-dev electron-builder
    ....
  • electron-builder@20.38.4
    added 173 packages from 106 contributors and audited 2087 packages in 22.04s
    found 0 vulnerabilities
    Switch to Powershell Admin

PS C:\Development\oracledb> npm install --global --production windows-build-tools
Now configuring the Visual Studio Build Tools..
....
All done!

oracledb@3.0.1 install C:\Development\oracledb\node_modules\oracledb
node-gyp rebuild

C:\Development\oracledb\node_modules\oracledb>if not defined npm_config_node_gyp (node "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\....\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Traceback (most recent call last):
File "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\gyp\gyp_main.py", line 13, in
import gyp
File "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp_init_.py", line 8, in
import gyp.input
File "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\gyp\pylib\gyp\input.py", line 5, in
from compiler.ast import Const
ImportError: No module named compiler.ast
gyp ERR! configure error
gyp ERR! stack Error: gyp failed with exit code: 1
gyp ERR! stack at ChildProcess.onCpExit (C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\configure.js:345:16)
gyp ERR! stack at ChildProcess.emit (events.js:182:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:237:12)
gyp ERR! System Windows_NT 10.0.17763
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\Mark D Drake\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Development\oracledb\node_modules\oracledb
gyp ERR! node -v v10.6.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
npm WARN enoent ENOENT: no such file or directory, open 'C:\Development\oracledb\package.json'
npm WARN oracledb No description
npm WARN oracledb No repository field.
npm WARN oracledb No README data
npm WARN oracledb No license field.

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! oracledb@3.0.1 install: node-gyp rebuild
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the oracledb@3.0.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\Mark D Drake\AppData\Roaming\npm-cache_logs\2019-01-10T17_26_21_716Z-debug.log

The problem appears to be related to the file compiler.ast, which is not found udner the node_modules
directory or the python installation. Googling implies I need to install pythondev package (at least that would be the solution for Linux), but I can't find any details on what to do in Windows..

FWITW I am using the Python distribution from Python.org

@cjbj
Copy link
Member

cjbj commented Jan 10, 2019

It's not clear why source code is being used instead of pre-built binaries. Didn't electron sort out its ABI incompatibilities a while back?

@markddrake
Copy link

markddrake commented Jan 11, 2019

Chris

Are you suggesting I should be able to to an npm install oracbledb and everything should work. If I do this then I get

Uncaught Error: NJS-045: cannot load the oracledb add-on binary for Node.js 10.2.0 (win32, x64) Cannot load C:\Development\YADAMU\oracle\node\node_modules\oracledb\build\Release\oracledb.node A dynamic link library (DLL) initialization routine failed. \?\C:\Development\YADAMU\oracle\node\node_modules\oracledb\build\Release\oracledb.node Node-oracledb installation instructions: https://oracle.github.io/node-oracledb/INSTALL.html You must have 64-bit Oracle client libraries in your PATH environment variable. If you do not have Oracle Database on this computer, then install the Instant Client Basic or Basic Light package from http://www.oracle.com/technetwork/topics/winx64soft-089540.html A Microsoft Visual Studio Redistributable suitable for your Oracle client library version must be available. at Object. (C:\Development\YADAM…\lib\oracledb.js:68) at Object. (C:\Development\YADAM…lib\oracledb.js:696) at Module._compile (internal/modules/cjs/loader.js:711) at Object.Module._extensions..js (internal/modules/cjs/loader.js:722) at Module.load (internal/modules/cjs/loader.js:620) at tryModuleLoad (internal/modules/cjs/loader.js:559) at Function.Module._load (internal/modules/cjs/loader.js:551) at Module.require (internal/modules/cjs/loader.js:658) at require (internal/modules/cjs/helpers.js:20) at Object. (C:\Development\YADAM…oracledb\index.js:1)

I do have the Oracle Instant client bin in my path before you ask. If I run a node app that uses oracledb from the same command window it works fine. Dan pointed me at this thread as a solution to the problem..

@cjbj
Copy link
Member

cjbj commented Jan 11, 2019

I was wondering why https://github.com/n-riesco/oracledb-electron-builder/blob/master/package.json#L59 used source and not just '~3.0' to get the binaries.

@n-riesco
Copy link
Author

n-riesco commented Jan 11, 2019

@cjbj I discussed the reason at the bottom of this comment.

In Windows, I found that electron fails to require the prebuilt binaries for node.

@cjbj
Copy link
Member

cjbj commented Jan 11, 2019

@n-riesco thanks for chiming in. Do you have any thoughts on @markddrake's issue?

@n-riesco
Copy link
Author

@cjbj

The logs show that node-gyp fails to run gyp (which is needed to build native modules from source). This suggests that the Python installation is broken.

@markddrake, are you able to run python -c "from compiler.ast import Const"?

@markddrake
Copy link

@n-riesco

C:\Users\Mark D Drake>python -c "from compiler.ast import Const"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ImportError: No module named compiler.ast

C:\Users\Mark D Drake>

And I can't find a file called compiler.ast on my computer..

FWiW I installed Python using

https://www.python.org/ftp/python/2.7.15/python-2.7.15.amd64.msi

@starvikas009
Copy link

Hi @n-riesco, thanks a lot for writing this!
Do you know if some changes are needed for latest version of NodeJS and electron? Which version of NodeJS were you using for this example repo 'oracledb-electron-rebuild'?

@n-riesco
Copy link
Author

@starvikas009 I used node-oracledb in Falcon. Falcon is using Node.js v8 and Electron v2.

@n-riesco
Copy link
Author

@markddrake Do you also have Python 3 on that machine?

What does python --version show?

If you get Python 3, that means you have both Python 2 and Python 3 in your machine and you need to tell npm which one to use; like this:

npm config set python /path/to/executable/python2.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants