Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error: constructor must explicitly initialize the base class Napi::ObjectWrap<> #1122

Closed
c4lliope opened this issue Jan 5, 2022 · 4 comments
Labels

Comments

@c4lliope
Copy link

c4lliope commented Jan 5, 2022

Based on Automattic/node-canvas#1868 (comment),
I have forked the npm canvas library to https://github.com/assembleco/node-canvas,
and am replacing nan using node-addon-api.

I am going from nan @2.15.0 to node-addon-api @4.2.0.
I ran the conversion tool, and obeyed everything in the setup doc.

When I run yarn,

...
gyp info using [email protected]
gyp info using [email protected] | darwin | x64
gyp info spawn make
gyp info spawn args [ 'BUILDTYPE=Release', '-C', 'build' ]
  SOLINK_MODULE(target) Release/canvas-postbuild.node
  CXX(target) Release/obj.target/canvas/src/backend/Backend.o
../src/backend/Backend.cc:4:10: error: constructor for 'Backend' must explicitly initialize the base class
      'Napi::ObjectWrap<Backend>' which does not have a default constructor
Backend::Backend(std::string name, int width, int height)
         ^
../node_modules/node-addon-api/napi.h:2046:9: note: 'Napi::ObjectWrap<Backend>' declared here
  class ObjectWrap : public InstanceWrap<T>, public Reference<Object> {
        ^
../src/backend/Backend.cc:18:76: error: member reference base type 'uint32_t' (aka 'unsigned int') is not a
      structure or union
  if (info[0].IsNumber()) width  = info[0].As<Napi::Number>().Uint32Value().FromMaybe(0);
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
../src/backend/Backend.cc:19:76: error: member reference base type 'uint32_t' (aka 'unsigned int') is not a
      structure or union
  if (info[1].IsNumber()) height = info[1].As<Napi::Number>().Uint32Value().FromMaybe(0);
                                   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~
../src/backend/Backend.cc:23:12: error: no member named 'Wrap' in 'Backend'
  backend->Wrap(info.This());
  ~~~~~~~  ^
../src/backend/Backend.cc:24:3: error: void function 'init' should not return a value [-Wreturn-type]
  return info.This();
  ^      ~~~~~~~~~~~
In file included from ../src/backend/Backend.cc:1:
../src/backend/Backend.h:60:14: warning: private field 'backend' is not used [-Wunused-private-field]
    Backend* backend;
             ^
1 warning and 5 errors generated.
make: *** [Release/obj.target/canvas/src/backend/Backend.o] Error 1

gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/Users/grace/.nvm/versions/node/v12.22.1/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Darwin 19.6.0
gyp ERR! command "/Users/grace/.nvm/versions/node/v12.22.1/bin/node" "/Users/grace/.nvm/versions/node/v12.22.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "build" "--fallback-to-build" "--module=/Users/grace/place/assemble/node-canvas/build/Release/canvas.node" "--module_name=canvas" "--module_path=/Users/grace/place/assemble/node-canvas/build/Release" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=0" "--node_napi_label=node-v72"
gyp ERR! cwd /Users/grace/place/assemble/node-canvas
gyp ERR! node -v v12.22.1
gyp ERR! node-gyp -v v5.1.0
gyp ERR! not ok

node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/Users/grace/.nvm/versions/node/v12.22.1/bin/node /Users/grace/.nvm/versions/node/v12.22.1/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js build --fallback-to-build --module=/Users/grace/place/assemble/node-canvas/build/Release/canvas.node --module_name=canvas --module_path=/Users/grace/place/assemble/node-canvas/build/Release --napi_version=8 --node_abi_napi=napi --napi_build_version=0 --node_napi_label=node-v72' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/Users/grace/place/assemble/node-canvas/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:314:20)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:1022:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
node-pre-gyp ERR! System Darwin 19.6.0
node-pre-gyp ERR! command "/Users/grace/.nvm/versions/node/v12.22.1/bin/node" "/Users/grace/place/assemble/node-canvas/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /Users/grace/place/assemble/node-canvas
node-pre-gyp ERR! node -v v12.22.1
node-pre-gyp ERR! node-pre-gyp -v v1.0.8
node-pre-gyp ERR! not ok 

This is a bunch, but I hope it's clear where the problem is coming from;
seems like the Backend constructor
is missing some setup code.

I can't quite figure out what code should go in this constructor, because it doesn't share the same structure as other constructors in the codebase, like Canvas,
which uses an ::Initialize function instead of a constructor.

I'm out of my depth here; though I do need a running copy of canvas using the node-addon-api.
If anyone has experience with this error, please recommend an approach.

I'm much obliged.
G

@KevinEady
Copy link
Contributor

Hi @c4lliope ,

If you look at the ObjectWrap example, you need to pass the CallbackInfo argument to the ObjectWrap constructor.

Does this help?

@mhdawson
Copy link
Member

mhdawson commented May 5, 2022

@c4lliope are you still looking at this? If so did @KevinEady suggestion help?

@github-actions
Copy link
Contributor

github-actions bot commented Aug 4, 2022

This issue is stale because it has been open many days with no activity. It will be closed soon unless the stale label is removed or a comment is made.

@github-actions github-actions bot added the stale label Aug 4, 2022
@mhdawson
Copy link
Member

mhdawson commented Aug 4, 2022

I'm going to close this since there was no response after Kevin's suggestions. Please let us know if that was not the right thing to do.

@mhdawson mhdawson closed this as completed Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants