October 16, 2021

Software Mile.com

Latest Software News and Hacks

Incomplete type error for napi.h – C++ addon for Node

I am creating C++ addons for Node and everything works good except Visual Studio is underlying all types from napi.h library and telling me that incomplete types are not allowed. When I compile it with node-gyp, everything is alright, but its little bit disturbing to see so many “reds” in my code in Visual Studio.

#include "test.h"
#include "../node_modules/node-addon-api/napi.h"

Napi::String helloFunc(const Napi::CallbackInfo& info) {
    Napi::Env env = info.Env();

    std::string name = (std::string)info[0].ToString();
    std::string result = helloUser(name);
    return Napi::String::New(env, result);

Napi::Object Init(Napi::Env env, Napi::Object exports) {
        Napi::String::New(env, "helloUser"),
        Napi::Function::New(env, helloFunc)

    return exports;

NODE_API_MODULE(greet, Init)

Go to Source of this post
Author Of this post: Matej Peluha
Title Of post: Incomplete type error for napi.h – C++ addon for Node
Author Link: {authorlink}