Node.js本机模块不是有效的Win32应用程序错误 [英] Node.js native module is not a valid Win32 application error
问题描述
尝试为node.js制作Hello World本机模块
Trying to make Hello World native module for node.js
使用一个文件在VS 2012中获得一个Win32项目:
Got an Win32 Project in VS 2012 with one file:
#include <node.h>
#include <v8.h>
using namespace v8;
Handle<Value> Method(const Arguments& args) {
HandleScope scope;
return scope.Close(String::New("world"));
}
void init(Handle<Object> target) {
target->Set(String::NewSymbol("hello"),
FunctionTemplate::New(Method)->GetFunction());
}
NODE_MODULE(hello, init)
那会编译到hello.node.
选项:
-动态库(.dll)
-不支持公共语言运行时
That`s compiles to hello.node.
Options:
- Dynamic Library (.dll)
- No Common Language Runtime Support
使用方式:
hello = require './hello'
console.log hello.hello()
它在本地计算机上运行(win8 x64,节点:0.8.12)
但是在远程服务器(Windows Server 2008 x64,节点:0.8.12,iisnode:0.1.21 x64,iis7)上,它将引发以下错误:
It works on local machine (win8 x64, node: 0.8.12)
But on remote server (windows server 2008 x64, node: 0.8.12, iisnode: 0.1.21 x64, iis7) it throws this error:
应用程序引发了未捕获的异常并被终止:错误:
%1不是有效的Win32应用程序.
Application has thrown an uncaught exception and is terminated: Error:
%1 is not a valid Win32 application.
C:\ inetpub \ test \ lib \ server \ hello.node
在Object.Module._extensions..node(module.js:485:11)
在Module.load(module.js:356:32)
在Function.Module._load(module.js:312:12)
在Module.require(module.js:362:17)
在要求时(module.js:378:17)
在对象. (C:\ inetpub \ test \ lib \ server \ index.js:32:9)
在Module._compile(module.js:449:26)
在Object.Module._extensions..js(module.js:467:10)
在Module.load(module.js:356:32)
在Function.Module._load(module.js:312:12)
C:\inetpub\test\lib\server\hello.node
at Object.Module._extensions..node (module.js:485:11)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at Object. (C:\inetpub\test\lib\server\index.js:32:9)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
我尝试过的事情:
玩应用程序池设置(启用Win32应用程序)无济于事.
Iisnode x86不能安装在x64操作系统上.
由于错误而无法编译为x64:错误2错误LNK1112:模块机器类型'X86'与目标机器类型'x64'冲突C:\ derby \ hello \ build \ node.lib(node.exe)你好
What I tryed:
Playing with app pool settings (enable win32 apps) does not helped.
Iisnode x86 does not install on x64 os.
Can`t compile to x64 because of error: Error 2 error LNK1112: module machine type 'X86' conflicts with target machine type 'x64' C:\derby\hello\build\node.lib(node.exe) hello
有人有什么建议吗?
推荐答案
我不知道是否为时已晚,但是经过反复试验,我找到了答案,主要的问题是(在我的机器上)我编译了nodejs在Windows上能够使用Visual C ++创建扩展,并且我已经从页面安装了Node.js,如果我尝试使用默认安装(由Node.js安装程序添加到PATH)运行测试, ,但是如果我使用已编译的node.exe(我编译后的那个文件能够在Visual C ++中引用这些库),那么它将起作用.
I dont know if it's too late, but I found the answer after some trial and error, mainly the problem (in my machine) was that I compiled the nodejs on windows to be able to create the extension using visual C++, and I already had installed the nodejs from the page, if I try to run the test using the default installation (which was added to my PATH by the nodejs installer) then it fails, but if I use the compiled node.exe (the one I compiled to be able to reference the libs in Visual C++) then it works.
总而言之,问题不在于扩展,而是与nodejs编译有关,请使用您编译的节点(为了构建VS解决方案,我假设您已经这样做了),然后它应该可以在远程计算机上工作.
In summary, the problem is not with the extension, it's with the nodejs compilation, use the node that you compiled (in order to build the VS solution I assume you did that) and then it should work on the remote machine.
注意:问题取决于您使用64位编译的node.exe运行32位dll,这就是为什么要抱怨的原因,如果您使用32位的node.exe应该可以工作. (至少解决了我的问题)
Note: The problem relies on that you're using node.exe compiled in 64bits to run a 32bits dll, that's why it's complaining, if you use node.exe in 32 bits it should work. (at least that solved my problem)
这篇关于Node.js本机模块不是有效的Win32应用程序错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!