Node.js native module is not a valid Win32 application error

前端 未结 4 1745
庸人自扰
庸人自扰 2021-02-07 05:11

Trying to make Hello World native module for node.js

Got an Win32 Project in VS 2012 with one file:

#include 

        
相关标签:
4条回答
  • 2021-02-07 05:38

    Just had the same problem and even though the architectures of my node and addon were identical, I got similar errors messages. It turns out that you can't rename the node executable. It has to be node.exe, I was trying to test multiple versions at the same time so I had to put them in their own folders. After that it all worked fine.

    0 讨论(0)
  • 2021-02-07 05:38

    Unrelated to your probem: I get the same error (Error: %1 is not a valid Win32 application) when trying to execute a script with extension ".node", e.g. node.exe example.node. Other extensions (.js, .txt, no extension at all) work fine.

    0 讨论(0)
  • 2021-02-07 05:42

    In my case, the issue was trying to execute an Electron app on Windows that was built (for Windows) using Linux. I solved by building it (for Windows) using Windows.

    To build it on windows I used the following commands:

    npm install --global-production windows-build-tools
    npm install
    npm run build:prod && electron-builder build --windows
    

    To execute the last command you need electron-builder, install it if you do not have with

    npm install --save-dev electron-builder
    
    0 讨论(0)
  • 2021-02-07 05:57

    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.

    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.

    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)

    0 讨论(0)
提交回复
热议问题