-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Prebuilt package throws "TypeError: Cannot read property 'call' of undefined" #1310
Comments
Could you post the entire stack trace? Thanks |
@LinusU, updated, thanks! |
Are you sure the issue is with prebuilds? I just reproduced the same stack trace, then forced a manual build and then got the same results again. It's a weird error, since require('canvas/lib/bindings').Image.prototype.setSource
[Function: setSource] |
(This is the same error as #1294 and #1250, both unresolved.) I can finally repro this (thanks!), and it seems to be because of Jest 😞 . The following works with mocha: const fs = require("fs");
const util = require("util");
const canvas = require("canvas");
const readFile = util.promisify(fs.readFile);
const {expect} = require("chai");
describe("Canvas test", () => {
it("Set Image.src", async () => {
const data = await readFile("./image.png");
const image = new canvas.Image;
await expect( () => { image.src = data;} ).to.not.throw();
});
}); I think this is because Jest breaks node's guarantee that (I've complained about this to the Jest folks and they won't change the behavior. It's caused problems in most public repos I've worked on though.) As much as I don't want to pander to Jest, we can move the @chearon it's defined there in the native code, but deleted here in the JS: Line 23 in 65ff59a
|
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
Should be fixed in |
Issue or Feature
I guess this is an issue with the pre-built fallback packages for certain environments. Also worth being aware that in my more complex application (not shown) I saw intermittent success of tests and functionality.
Steps to Reproduce
These simple Jest tests fail on my machine.
Your Environment
The text was updated successfully, but these errors were encountered: