I’m trying to create a simple Node.js addon using N-API on Windows. My goal is to output “hello world”. However, I’m encountering an error when trying to build the addon. I followed the standard instructions, but I’m getting the following error during the build process:
nothing.c
win_delay_load_hook.cc
nothing.vcxproj -> C:Users79832my-addonbuildRelease\nothing.lib
addon.cpp
C:Users79832my-addonsrcaddon.cpp(2,10): error C1083: Cannot open include file: 'napi.h': No such file or directory [C:Users79832my-addonbuildaddon.vcxproj]
gyp ERR! build error
gyp ERR! build error
gyp ERR! stack Error: `C:Program FilesMicrosoft Visual Studio2022CommunityMSBuildCurrentBinMSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.<anonymous> (C:Users79832AppDataRoamingnpmnode_modulesnode-gyplibbuild.js:216:23)
gyp ERR! stack at ChildProcess.emit (node:events:519:28)
gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
gyp ERR! System Windows_NT 10.0.19045
gyp ERR! command "C:\Program Files\nodejs\node.exe" "C:\Users\79832\AppData\Roaming\npm\node_modules\node-gyp\bin\node-gyp.js" "build"
gyp ERR! cwd C:Users79832my-addon
gyp ERR! node -v v20.16.0
gyp ERR! node-gyp -v v10.2.0
gyp ERR! not ok
binding.gyp:
{
"targets": [
{
"target_name": "addon",
"sources": [ "src/addon.cpp" ],
"include_dirs": [
"<!(node -p "require('node-addon-api').include")"
],
"dependencies": [
"<!(node -p "require('node-addon-api').gyp")"
]
}
]
}
addon.cpp:
#include <node_api.h>
#include <napi.h>
Napi::String HelloWorld(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
return Napi::String::New(env, "Hello, world!");
}
Napi::Object Init(Napi::Env env, Napi::Object exports) {
exports.Set(Napi::String::New(env, "hello"), Napi::Function::New(env, HelloWorld));
return exports;
}
NODE_API_MODULE(addon, Init)
I’m trying to create a simple Node.js addon using N-API on Windows. My goal is to output “hello world”. However, I’m encountering an error when trying to build the addon. I followed the standard instructions, but I’m getting the following error during the build process:
stepanevgen2013 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.