您的位置:首页 > 数据库 > Oracle

node-oracle windows下编译安装

2015-10-26 16:57 465 查看
摘要: node-oracle windows下编译安装下的记录

步骤

1安装 oracle 11g

oracle官网下载orcale 11g ,【现在还是别用10g了,反正我没有用】

2 安装 microsoft visual studio2012 express

使用
microsoft visual studio2013
安装没有成功,不过应该2013也可以。以后再试。

3 安装nodejs

最新版最好【暂时只能用node0.10版本的,0.12版本的不行】,npm在1.3.15版本以前
node-gyp
在编译时会调用
VCBuild.exe
,在vs2012下是找不到的
VCBuild.exe
的。

4 安装 oracle instant client

【32位系统选择对应的32位版本】


下载
Version 12.1.0.1.0
中的
instantclient-basic-windows.x64-12.1.0.1.0.zip
instantclient-sdk- windows.x64-12.1.0.1.0.zip
; 并把它们解压到
C:\instantclient_12_1
文件夹中, 由于两个 zip 中的文件各不相同, 所以合并到同一个文件夹也不会发生覆盖。

5 设置环境变量

OCI_INCLUDE_DIR=C:\instantclient_12_1\sdk\include
OCI_LIB_DIR=C:\instantclient_12_1\sdk\lib\msvc\vc11
OCI_VERSION=12
Path=c:\instantclient_12_1\vc11;c:\instantclient_12_1;...

确保 Path 中 c:\instantclient_12_1\vc11 在 c:\instantclient_12_1 前面,最好放在最前面,安装了oracle后,如果放到后面可能会调用oracle安装目录下的文件,放在后面时,有时候编译失败。
【在编译完成后,为了安装oracle官网的node-oracledb , 更改 OCI_LIB_DIR=C:\instantclient_12_1\sdk\lib\msvc, 原来编译好的 oracle驱动可以继续使用,也就是说,OCI_LIB_DIR只用于编译过程。】

6 安装 python2.7

安装
python2.7
,
3.x
版本不行,node-gyp不支
3.x
·,
环境变量path里添加
;C:\Python27
,如果安装了3.x版本的要从环境变量里移除!

7 安装 node-gyp

cmd命令窗口里:

npm install -g node-gyp

8 安装 node-oracle

cmd:

npm install -g oracle

建议全局安装,因为在不同的机器上需要编译不同的版本,省得再在协同开发时,导致不同人员的冲突,尤其是使用GIT时候。

错误处理

1 MSBUILD : error MSB3411: Could not load the Visual C++ component "VCBuild.exe".

报错内容:

MSBUILD : error MSB3411: Could not load the Visual C++ component "VCBuild.exe".
If the component is not installed, either 1) install the Microsoft Windows SDK
for Windows Server 2008 and .NET Framework 3.5, or 2) install Microsoft Visual
Studio 2008.  [C:\Users\Administrator\AppData\Roaming\npm\node_modules\oracle\
build\binding.sln]
gyp ERR! build error
gyp ERR! stack Error: `C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:267:23)
gyp ERR! stack     at ChildProcess.EventEmitter.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:789:12)
gyp ERR! System Windows_NT 6.1.7601
gyp ERR! command "node" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Administrator\AppData\Roaming\npm\node_modules\oracle
gyp ERR! node -v v0.10.21
gyp ERR! node-gyp -v v0.10.10
gyp ERR! not ok
npm ERR! weird error 1
npm ERR! not ok code 0

原因

npm在1.3.15版本以前
node-gyp
在编译时会调用
VCBuild.exe
,在vs2012下是找不到的
VCBuild.exe
,vs2012及以后版本是msbuild.exe作为编译器。

解决:

将npm 的 msvs的编译器设置为vs2012
cmd执行:

npm config set msvs_version 2012 --global

2 中文字符乱码

报错内容:

中文乱码

原因:

oracle 数据库和客户端需要统一设置字符编码;

解决:

建立oracle数据库时候设置数据库的字符编码 选择
utf-8
编码,默认设置中国的。

添加环境变量:

NLS_LANG=SIMPLIFIED CHINESE_CHINA.AL32UTF8

3 编译成功后,再安装完Oracle后无法加载node-oracle模块

错误描述:

在编译安装完成,并成功运行后,又安装 Oracle到本机,再次运行后,报错无法加载node-oracle模块。

原因:

编译时安装的模块是基于 instantclient_12_1进行编译的,以来模块也是instantclient_12_1,但再次安装oracle后,会在环境变量里的最前面添加:
c:\app\SatanRabbit\product\11.2.0\dbhome_1\bin;

\dbhome_1\bin 里面的 oci.dll 等于编译时配置的不一致,导致无法加载依赖项。

解决:

在环境变量 Path中,把
c:\app\SatanRabbit\product\11.2.0\dbhome_1\bin;
放置在
c:\instantclient_12_1
后面。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  node oracle node-oracle