Automattic / node-canvas

Node canvas is a Cairo backed Canvas implementation for NodeJS.
9.98k stars 1.15k forks source link

Electron-rebuild canvas 2.6.1 fails on Windows 10: Canvas.obj : error LNK2001: unresolved external symbol #1589

Open Sakari369 opened 4 years ago

Sakari369 commented 4 years ago

Issue or Feature

Build fails in Windows 10 x64 using electron-rebuild with Electron. Build works perfectly fine with just npm install canvas or building manually with node-gyp configure && node-gyp build.

Seems to be something incompatible with the canvas and the electron environment ? Building the canvas works perfectly fine with same setup in macOS Mojave.

The specific error reported by the compiler:

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

Steps to Reproduce

Install all the windows build prerequisities (GTK, libjpeg) in the locations provided by the install instructions.

Running

npx electron-rebuild canvas

Fails with the following message errors:

An unhandled error occurred inside electron-rebuild
gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@14.0.0 | win32 | x64
gyp info find Python using Python version 3.8.2 found at "C:\Python38\python.exe"
gyp http GET https://www.electronjs.org/headers/v8.2.0/node-v8.2.0-headers.tar.gz
gyp http 200 https://www.electronjs.org/headers/v8.2.0/node-v8.2.0-headers.tar.gz
gyp http GET https://www.electronjs.org/headers/v8.2.0/SHASUMS256.txt
gyp http GET https://www.electronjs.org/headers/v8.2.0/win-x86/node.lib
gyp http GET https://www.electronjs.org/headers/v8.2.0/win-x64/node.lib
gyp http GET https://www.electronjs.org/headers/v8.2.0/win-arm64/node.lib
gyp http 200 https://www.electronjs.org/headers/v8.2.0/win-x64/node.lib
gyp http 200 https://www.electronjs.org/headers/v8.2.0/SHASUMS256.txt
gyp http 200 https://www.electronjs.org/headers/v8.2.0/win-arm64/node.lib
gyp http 200 https://www.electronjs.org/headers/v8.2.0/win-x86/node.lib
gyp info find VS using VS2019 (16.6.30114.105) found at:
gyp info find VS "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community"
gyp info find VS run with --verbose for detailed information
gyp info spawn C:\Python38\python.exe
gyp info spawn args [
gyp info spawn args   'C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\node-gyp\\gyp\\gyp_main.py',
gyp info spawn args   'binding.gyp',
gyp info spawn args   '-f',
gyp info spawn args   'msvs',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\canvas\\build\\config.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\node-gyp\\addon.gypi',
gyp info spawn args   '-I',
gyp info spawn args   'C:\\Users\\sakari\\.electron-gyp\\8.2.0\\include\\node\\common.gypi',
gyp info spawn args   '-Dlibrary=shared_library',
gyp info spawn args   '-Dvisibility=default',
gyp info spawn args   '-Dnode_root_dir=C:\\Users\\sakari\\.electron-gyp\\8.2.0',
gyp info spawn args   '-Dnode_gyp_dir=C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\node-gyp',
gyp info spawn args   '-Dnode_lib_file=C:\\\\Users\\\\sakari\\\\.electron-gyp\\\\8.2.0\\\\<(target_arch)\\\\node.lib',
gyp info spawn args   '-Dmodule_root_dir=C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\canvas',
gyp info spawn args   '-Dnode_engine=v8',
gyp info spawn args   '--depth=.',
gyp info spawn args   '--no-parallel',
gyp info spawn args   '--generator-output',
gyp info spawn args   'C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\canvas\\build',
gyp info spawn args   '-Goutput_dir=.'
gyp info spawn args ]
gyp info spawn C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe
gyp info spawn args [
gyp info spawn args   'build/binding.sln',
gyp info spawn args   '/clp:Verbosity=minimal',
gyp info spawn args   '/nologo',
gyp info spawn args   '/p:Configuration=Release;Platform=x64'
gyp info spawn args ]
Building the projects in this solution one at a time. To enable parallel build, please add the "-m" switch.
  Copying C:/libjpeg-turbo64/bin/jpeg62.dll to C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\Release\\jpeg62.dll
          1 file(s) copied.
  Backend.cc
  ImageBackend.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\ImageBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\Backend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\ImageBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\Backend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  PdfBackend.cc
  SvgBackend.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\PdfBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\PdfBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\SvgBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\backend\SvgBackend.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  BMPParser.cc
  Backends.cc
  Canvas.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Backends.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Backends.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Canvas.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Canvas.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  CanvasGradient.cc
  CanvasPattern.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasGradient.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasGradient.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  CanvasRenderingContext2d.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasPattern.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasPattern.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  closure.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasRenderingContext2d.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\CanvasRenderingContext2d.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  color.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\closure.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\closure.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  Image.cc
  ImageData.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Image.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\Image.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\ImageData.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\ImageData.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
  init.cc
  register_font.cc
  win_delay_load_hook.cc
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8923,39): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\init.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\.electron-gyp\8.2.0\include\node\v8.h(8931,42): warning C4996: 'v8::MicrotasksCompletedCallback': Use *WithData version. (compiling source file ..\src\init.cc) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
     Creating library C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\Release\canvas.lib and object C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\Release\canvas.exp
Canvas.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ) [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\Release\canvas.node : fatal error LNK1120: 1 unresolved externals [C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas\build\canvas.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Users\sakari\dvl\omg-standalone\electron\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack     at ChildProcess.emit (events.js:315:20)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:276:12)
gyp ERR! System Windows_NT 10.0.18363
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild" "--target=8.2.0" "--arch=x64" "--dist-url=https://www.electronjs.org/headers" "--build-from-source" "--module_name=canvas" "--module_path=C:\\Users\\sakari\\dvl\\omg-standalone\\electron\\node_modules\\canvas\\build\\Release" "--host=https://github.com/node-gfx/node-canvas-prebuilt/releases/download/" "--remote_path=v2.6.1" "--package_name=canvas-v2.6.1-electron-v8.2-win32-unknown-x64.tar.gz"
gyp ERR! cwd C:\Users\sakari\dvl\omg-standalone\electron\node_modules\canvas
gyp ERR! node -v v14.0.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! not ok

Failed with exit code: 1

This line being the culprit:

Canvas.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::sharedptr cdecl v8::ArrayBuffer::GetBackingStore(void)" (imp?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ)

Your Environment

Electron 8.2.0, electron-rebuild 1.11.0 on Windows 10 x64. MSVC2019 Community edition

λ node --version
v14.0.0

Any help is appreciated! Anybody got the canvas module rebuilt in Windows using electron-rebuild ? Thank you.

Sakari369 commented 4 years ago

Seems this has something to do with:

https://github.com/nodejs/node/pull/30339: src: migrate to newer V8 ArrayBuffer APIs ?

V8 deprecates GetContents() in favour of GetBackingStore().

Don't really understand enough of the Electron build process to figure out why the build fails with the Electron v8 using electron-rebuild.

Tested with newest Electron 9 also, which should include v8 8.3, which should have this change already made in it.

Downgraded my Node from 14.x to the LTS release 12.16.3 but no success either there.

Thosty commented 4 years ago

I had the same problem with version 2.14.1 of nan. After switching back to 2.14.0 everything works.

Sakari369 commented 4 years ago

Thank you @Thosty , this indeed fixed the compilation problem! Will report the bug to the nan repository.

Sakari369 commented 4 years ago

Will close this issue as not directly a node-canvas issue, installing nan v2.14.0 manually fixed the problem.

nkhs commented 3 years ago

I installed "nan": "2.13.2" in node_modules/canvas with below command cd node_modules npm i nan@2.13.2

And, This is working

Node: 14.16.0 electron: "^12.0.1", electron-builder: "^20.19.2",

wxfred commented 3 years ago

@nkhs @Sakari369 not working for me

Win10 Node v14.17.3 Electron v12.0.14 nan v2.13.2 or v2.14.0

By the way, my mac is fine.

Sakari369 commented 3 years ago

@wxfred Yeah no idea about Windows. Seems with these problems the solution is to try install and re-install different versions.

Sakari369 commented 2 years ago

Faced this issue again when rebuilding node-canvas for Windows 10. @wxfred installing nan@2.14.0 manually fixed this for me, as mentioned before by Thosty.

wxfred commented 2 years ago

@Sakari369 Thanks a lot, I made it with

win10 node v14.17.3 electron v11.4.10 canvas v2.6.1 nan v2.14.0

But, Pattern is not implemented in node-canvas 2.6.1 according to https://github.com/Automattic/node-canvas/pull/1623#commits-pushed-379a650 It will be another nightmare for me when the new version come out.

hrueger commented 2 years ago

I have the same problem. Is there any "official" solution coming? The versions @wxfred provided don't work for me...

EvanBldy commented 1 year ago

I have the same problem with newest versions... Is there a fix for that?

GitMurf commented 1 year ago

I have same problem as well. Have been troubleshooting for weeks and cannot find a workaround / solution. This is very frustrating because node-canvas is a dependency in many packages so it not only effects node-canvas but most packages that utilize.

Has anyone figured out a decent workaround? I am fine if it is super hacky for the time being. Thanks!

Sakari369 commented 1 year ago

Hey @GitMurf , did you find any solution for this ? Or @EvanBldy ?

Seems this failure happens again with Electron 24 and newest or older version of canvas on Windows 10. on macOS this works just fine.

Fixing nan package to 2.14.0 no longer works it seems.

Might have to spend some time looking into this.

GitMurf commented 1 year ago

@Sakari369 good news! The solution was essentially that canvas needed to migrate to using node addon api instead of nan. Here are details: https://github.com/Automattic/node-canvas/issues/923

And lucky for you with this timing, @chearon just submitted a PR for this (months ... really years, in the making!) https://github.com/Automattic/node-canvas/pull/2235

Sakari369 commented 1 year ago

@Sakari369 good news! The solution was essentially that canvas needed to migrate to using node addon api instead of nan. Here are details: #923

And lucky for you with this timing, @chearon just submitted a PR for this (months ... really years, in the making!) #2235

Good news! Thanks for sharing 🙂 Did not completely understand if this would fix the issue, but apparently yes ?

I was mentally prepared to spend couple of days to find a quick fix for this somehow, but happy that this issue might be fixed for good with the migration to n-api.

Have you tested the branch with the pr ?

GitMurf commented 1 year ago

Have you tested the branch with the pr ?

I have not tested it yet. Priorities have shifted for my application so it isn't as urgent anymore so I will test when it gets officially released.

I was mentally prepared to spend couple of days to find a quick fix for this somehow...

I thought that as well and after weeks of attempts I realized there really wasn't a "quick fix" so good thing you avoided that rabbit hole ;-)

Sakari369 commented 1 year ago

Have you tested the branch with the pr ?

I have not tested it yet. Priorities have shifted for my application so it isn't as urgent anymore so I will test when it gets officially released.

I was mentally prepared to spend couple of days to find a quick fix for this somehow...

I thought that as well and after weeks of attempts I realized there really wasn't a "quick fix" so good thing you avoided that rabbit hole ;-)

Have you tested the branch with the pr ?

I have not tested it yet. Priorities have shifted for my application so it isn't as urgent anymore so I will test when it gets officially released.

I was mentally prepared to spend couple of days to find a quick fix for this somehow...

I thought that as well and after weeks of attempts I realized there really wasn't a "quick fix" so good thing you avoided that rabbit hole ;-)

Thanks for the info! Will give it a spin probably soon, hoping to give some feedback also from that if it's working on both macOS and Windows with electron.

Yeah.. okay good to know that :)

alexthegoodman commented 1 year ago

@GitMurf I am developing an Electron app that relies on canvas like many others. It looks like there is an open PR for N-API. I installed it and my build now runs successfully.

image
GitMurf commented 1 year ago

@GitMurf I am developing an Electron app that relies on canvas like many others. It looks like there is an open PR for N-API. I installed it and my build now runs successfully.

Thanks for confirming it works even "as is" before it gets merged. Great news! I'll probably get around to testing it next week.

chroods commented 1 year ago

i have the same problem but in my case i am having this problem because of a library i am using

uchiha-itachi95 commented 8 months ago

The issue still persists. Tried doing npm i Automattic/node-canvas#c32c39bf5b65cb3409f37602d2e59818d0d5e892 but still same issue.

space-rodeo commented 3 weeks ago

I am having the same problem while including the latest version of Automattic/node-canvas. Has there been any new updates or ways to resolve this issue in the past several months?

GitMurf commented 3 weeks ago

I am having the same problem while including the latest version of Automattic/node-canvas. Has there been any new updates or ways to resolve this issue in the past several months?

Unfortunately I don't think so. @chearon do you know what current status is? Thanks!