nan: Electron-rebuild canvas fails with nan 2.14.1, works with 2.14.0

Hey, I had trouble trying to figure out why running

npx electron-rebuild canvas

Failed with the following error on Windows 10 x64:

Canvas.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)

I reported the issue to to the node-canvas repository here: https://github.com/Automattic/node-canvas/issues/1589

With more detail about the issue. Somebody figured out nan 2.14.1 was the culprit, downgrading manually to nan 2.14.0 with

npm install nan@2.14.0

Fixed the compilation.

About this issue

  • Original URL
  • State: open
  • Created 6 years ago
  • Reactions: 1
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I’m pretty sure this is an error in how electron is built for windows, I have created a bug report here: https://github.com/electron/electron/issues/29893 Going back to nan 2.14.0 won’t work if you want to build for electron 13 or later as the old api got removed.

Problem still here on Electron v16.0.1 with canvas 2.8.0 and nan 2.15.0 on Windows 10 (Here’s the full thing original issue. Still showing the main error mentioned in this issue’s body by @Sakari369. Really frustrated having to deal with all this hassle while only wanting to code a simple app using canvas.

@wxfred tl;dr: So the solution currently would be to build modules with clang, which, to be completely honest, is a massive pita on windows atm.

Contrary to what I said earlier this isn’t because of a bug in electron but because electron is built with clang now, which uses libc++ for its implementation of the stl. If you build your native module with msvc or gcc, they will (by default) use their own implementation of the stl which isn’t binary compatible which could then lead to crashes at runtime. To avoid this libc++ changes the exported name of affected functions (adding a namespace called __1) which means the error happens at linktime instead of runtime.

The solution would be to build your native module with libc++, same as electron itself, but afaik the stl implementation is tightly tied with the compiler so you probably can’t just use msvc with libc++, you have to use the compiler it’s intended for.

node-gyp for example unfortunately isn’t designed to let you use clang on windows.

This is where I am atm, I haven’t yet managed to build my modules with clang and I’d rather make the switch to napi instead, seems like a better use of the time long term (plus I’d rather code than fight build systems)

Had the same issue with nodejs 14 and electron 11. Both claim to use v8 >= 8.

I manually edited the file from the commit 2c023bd in “./node_modules/canvas/node_modules/nan/nan_typedarray_contents.h” to use the old api. That made it working for me.

I wanted to look into this issue, but apparently it is fixed now? @Sakari369 could you please confirm

Will take a look as soon as I’m looking into the build process of my sw yet again, might take a while …