rebuild icon indicating copy to clipboard operation
rebuild copied to clipboard

Failed Rebuilding canvas: error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingStore(void)"

Open devyetii opened this issue 3 years ago • 20 comments

Well, I have a dead simple Electron app with only canvas and nan as dependencies alongside electron and react, running on a Windows 11 (21H2) machine.

What I'm trying to do is to rebuild canvas for electron using electron-rebuild. However, It's failing with the following error :

Canvas.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBackingSto
re(void)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ) referenced in function "void __cdecl parsePNGArgs(class v8::Local<class
v8::Value>,struct PngClosure &)" (?parsePNGArgs@@YAXV?$Local@VValue@v8@@@v8@@AEAUPngClosure@@@Z) [C:\Users\ebrah\Desktop\NFT_Generator-master\node_modules\canvas\build\ca
nvas.vcxproj]
CanvasRenderingContext2d.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuf
fer::GetBackingStore(void)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ) [C:\Users\ebrah\Desktop\NFT_Generator-master\node_modu
les\canvas\build\canvas.vcxproj]
ImageData.obj : error LNK2001: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> __cdecl v8::ArrayBuffer::GetBacking
Store(void)" (__imp_?GetBackingStore@ArrayBuffer@v8@@QEAA?AV?$shared_ptr@VBackingStore@v8@@@std@@XZ) [C:\Users\ebrah\Desktop\NFT_Generator-master\node_modules\canvas\buil
d\canvas.vcxproj]
C:\Users\ebrah\Desktop\NFT_Generator-master\node_modules\canvas\build\Release\canvas.node : fatal error LNK1120: 1 unresolved externals [C:\Users\ebrah\Desktop\NFT_Genera
tor-master\node_modules\canvas\build\canvas.vcxproj]

Here are ALL my system/app information

  • Operating System image

  • Architecture : x64 (Typical Intel Core-I7 processor 9750H)

  • Global Environment

    • Node v16.9.1 (using nvm)
    • NPM 7.21.1
    • node-gyp v8.4.0
  • Application Details

    • Dependencies
    "dependencies": {
        "canvas": "2.8.0",
        "electron": "16.0.1",
        "nan": "2.15.0",
        "react": "^16.13.1",
        "react-dom": "^16.13.1"
    },
    "devDependencies": {
        "@babel/core": "^7.11.6",
        "@babel/preset-env": "^7.11.5",
        "@babel/preset-react": "^7.10.4",
        "babel-loader": "^8.1.0",
        "css-loader": "^4.3.0",
        "electron-rebuild": "^3.2.5",
        "electron-reload": "^1.5.0",
        "sass": "^1.26.11",
        "sass-loader": "^10.0.2",
        "style-loader": "^1.2.1",
        "webpack": "^5.64.1",
        "webpack-cli": "^4.9.1"
    }
    

What I was doing

After running npm i I ran npm run rebuild which delegates to electron-rebuild -f -w canvas, and the error showed up along with some other warnings

What I was expecting

canvas to be built correctly to the correct version of electron I'm using, for this error to stop ruining my business. image

Waiting for your reply.

P.S. This is how the executon of electron-rebuild looks like on Git Bash / CMD on windows (also the same applies for electron-rebuild.cmd)

ezgif-3-465f949847a1

devyetii avatar Nov 21 '21 07:11 devyetii

facing the smae issue with isolated-vm but it does'nt include any of the named dependencies, did you find any other work around?

LuvbCa avatar Dec 10 '21 15:12 LuvbCa

Any progress?

JSoon avatar Dec 20 '21 06:12 JSoon

Me too the same problem. I use electron 16.0.5. and then try 17.0.0 also throw this error: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> this node.lib is only 800K. node 16.9.1's node-gyp's node.lib is 12M.

What does the electron-rebuild's node.lib come from??

wyklion avatar Dec 24 '21 09:12 wyklion

Me too the same problem. I use electron 16.0.5. and then try 17.0.0 also throw this error: unresolved external symbol "__declspec(dllimport) public: class std::shared_ptr<class v8::BackingStore> this node.lib is only 800K. node 16.9.1's node-gyp's node.lib is 12M.

What does the electron-rebuild's node.lib come from??

It turns out that if u do not need to use canvas in Node.js environment, then this error will not emerge. My problem is that I only use canvas in the renderer progress, but due to my misuse requiring it in the main progress, so please make sure whether you really need to rebuild node-canvas module first.

JSoon avatar Dec 24 '21 09:12 JSoon

i need to build my C++ code to .node with node-gyp. js input ArrayBuffer to c++, or C++ output to Js. So i use the code std::shared_ptr<BackingStore> data = args[1].As<ArrayBuffer>()->GetBackingStore(); I dont know what matter about canvas.

wyklion avatar Dec 24 '21 09:12 wyklion

@JSoon 哦,所以成都人你看懂我说的了吗。 就这个electron-rebuild的node库就不对呀它自己缩减了。 我得用它编成跟electron版本一致的。 直接用node16.9.1编是能编过的。

wyklion avatar Dec 24 '21 10:12 wyklion

你参考下我这边文章呢😀 @wyklion 希望由帮助.

JSoon avatar Dec 24 '21 10:12 JSoon

@JSoon 文章在哪呢。。。

wyklion avatar Dec 24 '21 10:12 wyklion

Did you guys find anything interesting? I sadly don't understand a single word and google translator doesn't help much.

LuvbCa avatar Dec 25 '21 13:12 LuvbCa

Sorry that I couldn't follow up with this thread. Actually I separated the logic that requires canvas in a separate Nodejs Backend app and used OS APIs of electron to run it when required. Actually felt really sorry not managing to work this problem out.

devyetii avatar Dec 25 '21 13:12 devyetii

Yeah, seems like this is the only viable option. Thanks anyways. If i find something interesting i'll let you know. and of course Happy Christmas

LuvbCa avatar Dec 25 '21 14:12 LuvbCa

http://jsoon.fun/front-end/views/blog-electron-node-canvas/index.html#windows-%E4%B8%8B%E6%89%93%E5%8C%85%E6%97%B6%E5%8F%AF%E8%83%BD%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98%E5%8F%8A%E6%B3%A8%E6%84%8F%E9%A1%B9

@wyklion

JSoon avatar Dec 27 '21 05:12 JSoon

Sorry that I couldn't follow up with this thread. Actually I separated the logic that requires canvas in a separate Nodejs Backend app and used OS APIs of electron to run it when required. Actually felt really sorry not managing to work this problem out.

@devyetii Sorry i didn't know much about electron, what do you means about OS API ? Do you have a documentation or a code sample ? I'm struggling with the same error since 3 days

Asabbagh404 avatar Mar 18 '22 13:03 Asabbagh404

I found that: https://www.npmjs.com/package/@napi-rs/canvas could solve problems but i'm not sure

Asabbagh404 avatar Mar 18 '22 13:03 Asabbagh404

Seems same issue. https://github.com/electron/electron/issues/29893

sengokyu avatar Apr 29 '22 12:04 sengokyu

http://jsoon.fun/front-end/views/blog-electron-node-canvas/index.html#windows-%E4%B8%8B%E6%89%93%E5%8C%85%E6%97%B6%E5%8F%AF%E8%83%BD%E9%81%87%E5%88%B0%E7%9A%84%E9%97%AE%E9%A2%98%E5%8F%8A%E6%B3%A8%E6%84%8F%E9%A1%B9

@wyklion

@JSoon 我按照上面流程一样的错误,你用的electron版本多少呢

lqomg avatar Nov 23 '22 05:11 lqomg

@JSoon 哦,所以成都人你看懂我说的了吗。 就这个electron-rebuild的node库就不对呀它自己缩减了。 我得用它编成跟electron版本一致的。 直接用node16.9.1编是能编过的。

搞定了么大兄弟? @wyklion 我也遇见了

lqomg avatar Nov 23 '22 09:11 lqomg

I am having the exact same issue. Is this still not resolved? It has been almost a year since initial Issue was opened. Has anyone figured out any viable workarounds? Thanks!

GitMurf avatar Nov 24 '22 17:11 GitMurf

I found that: https://www.npmjs.com/package/@napi-rs/canvas could solve problems but i'm not sure

workd for me.

I case you use it: replace CanvasRenderingContext2D with SKRSContext2D

Full log on my machine: https://gist.github.com/hansSchall/621b030d3cbde724178b427707b1219a

hansSchall avatar Aug 01 '23 13:08 hansSchall

This can now be closed with recent merged PR for node-canvas moving to the node-addon-api 🎉 https://github.com/Automattic/node-canvas/pull/2235

GitMurf avatar Sep 27 '23 04:09 GitMurf