nodesj的addon模块配置使用&报错处理

来源:互联网 发布:js 通过元素值 查找 编辑:程序博客网 时间:2024/06/06 02:58

需要有C++文件,编译配置文件以及nodejs调用文件;

需要用到的命令node-gyp configure build;

具体见官方文档。


关于node-gyp的安装使用:

node-gyp的github链接:https://github.com/nodejs/node-gyp


github上的installation中给出了必须的环境,我的是win8,所以就记录一下win8的环境搭建:

1、npm install node-gyp@latest -g

测试:node-gyp list  显示出已安装的node development files则安装成功

如果报错command not found,需要安装工具(见【error】npm安装express报错: command not found),安装了express-generator以后node-gyp也正常了,不过不知道是不是这个原因0 0


2、安装 Python (v2.7.10 recommended, v3.x.x is not supported)

安装完需要将Python的安装路径加到计算机》属性》高级系统设置》环境变量》系统变量path中去,记得加分号

测试:cmd中输入python -V  输出版本号,注意V是大写(不知道为何gitbash中就没有python命令= =)


3、安装 Microsoft Visual Studio C++ 2013 for Windows Desktop (Express version works well)

建议下载几百M的那个,比较快,下下来再慢慢装



各种node-gyp的报错:

1、先自查:node-gyp是否为最新版本,python是否正确安装且为v2.7,VS是否安装,是否关闭代理,是否有binding.gyp文件,c文件代码是否正确。


2、node-gyp版本问题,解决方案:uninstall以后安装最新版本

$ node-gyp configure
gyp info it worked if it ends with ok
gyp info using node-gyp@3.3.1
gyp info using node@5.7.1 | win32 | x64
gyp http GET https://nodejs.org/download/release/v5.7.1/node-v5.7.1-headers.tar.                                                                                               gz
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: read ECONNRESET
gyp ERR! stack     at exports._errnoException (util.js:856:11)
gyp ERR! stack     at TLSWrap.onread (net.js:550:26)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\XXX\\AppD                                                                                               ata\\Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure"
gyp ERR! cwd C:\Users\XXX
gyp ERR! node -v v5.7.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok


3、没有binding.gyp文件或者格式不正确

gyp: binding.gyp not found (cwd: C:\Users\XXX) while trying to                                                                                           load binding.gyp
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (C:\Users\XXX\AppData\Roaming\npm\nod                                                                                          e_modules\node-gyp\lib\configure.js:305:16)
gyp ERR! stack     at emitTwo (events.js:100:13)
gyp ERR! stack     at ChildProcess.emit (events.js:185:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:                                                                                          200:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\XXX\\AppData\\                                                                                          Roaming\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "configure"
gyp ERR! cwd C:\Users\XXX
gyp ERR! node -v v5.7.1
gyp ERR! node-gyp -v v3.3.1
gyp ERR! not ok


0 0