question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

error when using node-canvas alpha.8

See original GitHub issue

my package.json versions

“canvas”: “2.0.0-alpha.8” “chart.js”: “^2.7.1”, “chartjs-node”: “^1.6.0”,


When using "canvas": "^2.0.0-alpha.2", node-chartjs works like a charm, when using "canvas": "^2.0.0-alpha.8", item is null in acquireContext so item.length errors in platform.dom.js

	acquireContext: function(item, config) {
		if (typeof item === 'string') {
			item = document.getElementById(item);
		} else if (item.length) {
			// Support for array based queries (such as jQuery)
			item = item[0];
		}

		if (item && item.canvas) {
			// Support for any object associated to a canvas (including a context2d)
			item = item.canvas;
		}

		// To prevent canvas fingerprinting, some add-ons undefine the getContext
		// method, for example: https://github.com/kkapsner/CanvasBlocker
		// https://github.com/chartjs/Chart.js/issues/2807
		var context = item && item.getContext && item.getContext('2d');

		// `instanceof HTMLCanvasElement/CanvasRenderingContext2D` fails when the item is
		// inside an iframe or when running in a protected environment. We could guess the
		// types from their toString() value but let's keep things flexible and assume it's
		// a sufficient condition if the item has a context2D which has item as `canvas`.
		// https://github.com/chartjs/Chart.js/issues/3887
		// https://github.com/chartjs/Chart.js/issues/4102
		// https://github.com/chartjs/Chart.js/issues/4152
		if (context && context.canvas === item) {
			initCanvas(item, config);
			return context;
		}

		return null;
	},

Can someone please help me and tell me what im doing wrong?

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:11

github_iconTop GitHub Comments

2reactions
thofnarcommented, Nov 15, 2018

@gonnza thanks! I ended up downgrading to canvas 1.6.13 and that is working just fine. Thanks for the input, that definitely helped me out! 😃

1reaction
trysheepycommented, Feb 22, 2019

bump, also having this problem with canvas 2.x, but resolves with older versions. Any updates on why this is happening with recent versions?

The error is: “Unhandled rejection TypeError: Cannot read property ‘length’ of null”.

node: 8.11.3 chartjs-node: 1.7.1 chart.js: 2.7.3 canvas: 2.3.1 OS: Mac 10.14.2

Any better solutions than just downgrading the canvas version?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Error running canvas on node.js v10.17 #1498 - GitHub
When trying to run canvas on node.js v10.17 I get this error: (node:22368) ... was compiled against a different Node.js version using
Read more >
Support - NodeCanvas
Get help and post issues here.
Read more >
node-canvas - npm
node-canvas. This is the documentation for version 2.0.0-alpha. Alpha versions of 2.0 can be installed using npm install canvas@next .
Read more >
node canvas on alpine within docker - Stack Overflow
OK, here's an answer--a way to install node-canvas v2.5 under the official node:10.16.0-alpine Docker image. As you probably know, the error ...
Read more >
canvas-prebuilt | Yarn - Package Manager
This is a drop-in replacement for canvas that does not require any compiling. To use it just npm install canvas-prebuilt or replace canvas...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found