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

Installing from github can create a C++/JS mismatch because of prebuilds #1250

Closed
lilyissillyyy opened this issue Sep 20, 2018 · 8 comments
Closed
Labels

Comments

@lilyissillyyy
Copy link
Contributor

Issue or Feature

Trying to call loadImage results in a TypeError (run with a Discord bot's eval command):

TypeError: Cannot read property 'call' of undefined
     at setSource (/root/xiao/node_modules/canvas/lib/image.js:102:14)
     at Image.set (/root/xiao/node_modules/canvas/lib/image.js:65:9)
     at Promise (/root/xiao/node_modules/canvas/index.js:34:15)
     at new Promise (<anonymous>)
     at loadImage (/root/xiao/node_modules/canvas/index.js:23:10)
     at eval (eval at run (/root/xiao/node_modules/discord.js-commando/src/commands/util/eval.js:57:22), <anonymous>:2:1)
     at EvalCommand.run (/root/xiao/node_modules/discord.js-commando/src/commands/util/eval.js:57:22)
     at CommandoMessage.run (/root/xiao/node_modules/discord.js-commando/src/extensions/message.js:214:34)

This does not happen until 1046abf, using 5301420 works as expected.

Steps to Reproduce

const { loadImage } = require('canvas');
loadImage(<Buffer or path>);

Your Environment

  • Version of node-canvas (e.g. 1.4.0): 1046abf
  • Environment (e.g. node 4.2.0 on Mac OS X 10.8): Ubuntu 18.04.1
@zbjornson
Copy link
Collaborator

I can't reproduce this using a local file path or a Buffer, and there's heavy usage of loadImage in the test suite. Do you have more info?

@lilyissillyyy
Copy link
Contributor Author

https://github.com/dragonfire535/xiao/tree/master/commands/image-edit none of the commands in this collection here that use loadImage work, all throw the error seen above on the latest commit.

@zbjornson
Copy link
Collaborator

No release has been made with 1046abf yet, so I assume you're installing from github? Did you rebuild the module?

@lilyissillyyy
Copy link
Contributor Author

lilyissillyyy commented Sep 20, 2018

I am installing from github, and yes at first, but the prebuild installed after, and still doesn't work.

@zbjornson
Copy link
Collaborator

^ Did you rebuild after pulling? There was a change in the C++ code in that commit, which requires rebuilding the module.

@lilyissillyyy
Copy link
Contributor Author

It works when providing --build-from-source to the install, so that's likely the reason. The prebuild, however, is currently broken.

@zbjornson
Copy link
Collaborator

Ah, node-pre-gyp will fetch the latest prebuild, which in this case creates a mismatch between the JS and C++. That should be fixable from the install script, but you found the workaround (--build-from-source).

(Heads-up, I'm going to change this issue's title to reflect that.)

@zbjornson zbjornson changed the title loadImage throws a TypeError Installing from github can create a C++/JS mismatch because of prebuilds Sep 20, 2018
zbjornson added a commit to zbjornson/node-canvas that referenced this issue Nov 29, 2018
Jest re-evaluates modules, whereas `require` is only supposed to evaluate them once. Fix: make reloading lib/image.js safe.

Fixes Automattic#1310
Fixes Automattic#1294
Fixes Automattic#1250
zbjornson added a commit that referenced this issue Dec 2, 2018
Jest re-evaluates modules, whereas `require` is only supposed to evaluate them once. Fix: make reloading lib/image.js safe.

Fixes #1310
Fixes #1294
Fixes #1250
@LinusU
Copy link
Collaborator

LinusU commented Dec 3, 2018

Should be fixed in 2.2.0 🚀

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