chartjs-node icon indicating copy to clipboard operation
chartjs-node copied to clipboard

error when using node-canvas alpha.8

Open pedall opened this issue 7 years ago • 11 comments

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?

pedall avatar Dec 16 '17 23:12 pedall

I was getting the same exact error. It seemed that Canvas was returning null for getContext. I tried looking into the canvas module but kept getting this error: "Too many levels of symbolic links" so I just removed the folder and reinstalled it with npm and that did the trick.

nollybear avatar Jan 03 '18 00:01 nollybear

same problem for me : "canvas": "2.0.0-alpha.11", "chart.js": "^2.7.2", "chartjs-node": "^1.6.1",

error :

Unhandled rejection TypeError: Cannot read property 'length' of null
    at Object.acquireContext (/Users/xxx/Documents/xxx/Docker/xxx/node_modules/chart.js/src/platforms/platform.dom.js:340:19)
    at Chart.construct (/Users/xxx/Documents/xxx/Docker/xxx/node_modules/chart.js/src/core/core.controller.js:79:27)

Mac OS X 10.13.3, node v8.9.3

djaoka avatar Mar 12 '18 09:03 djaoka

Same problem for me tried 2.0.0-alpha.8? Any solutions or fixes to this would be great.

mjlocke0529 avatar Mar 13 '18 17:03 mjlocke0529

which platform Windows or Linux

Vishallimgire avatar Aug 14 '18 05:08 Vishallimgire

I have also got the error in windows platform but when I used Ubuntu it works fine. I got an error in windows after installation of canvas 2.0.0-alpha.13

xyz\node_modules\bluebird\js\release\async.js:61
        fn = function () { throw arg; };
                           ^

TypeError: Cannot read property 'length' of null
at Object.acquireContext (E:\app_server\node_modules\chart.js\src\platforms\platform.dom.js:340:19)
at Chart.construct (E:app_server\node_modules\chart.js\src\core\core.controller.js:79:27)
at new Chart (E:\app_server\node_modules\chart.js\src\core\core.js:42:8)
at jsdom.envAsync.then.window (E:\app_server\node_modules\chartjs-node\index.js:106:31)
at tryCatcher (E:\app_server\node_modules\bluebird\js\release\util.js:16:23)
at Promise._settlePromiseFromHandler (E:\app_server\node_modules\bluebird\js\release\promise.js:512:31)
at Promise._settlePromise (E:\app_server\node_modules\bluebird\js\release\promise.js:569:18)
at Promise._settlePromise0 (E:\app_server\node_modules\bluebird\js\release\promise.js:614:10)
at Promise._settlePromises (E:\app_server\node_modules\bluebird\js\release\promise.js:693:18)
at Promise._fulfill (E:\app_server\node_modules\bluebird\js\release\promise.js:638:18)
at Object.done (E:\app_server\node_modules\bluebird\js\release\nodeback.js:42:21)
at process.nextTick (E:\app_server\node_modules\jsdom\lib\jsdom.js:320:18)
at _combinedTickCallback (internal/process/next_tick.js:131:7)
at process._tickCallback (internal/process/next_tick.js:180:9)

Vishallimgire avatar Aug 14 '18 05:08 Vishallimgire

still not resolved :(

I am getting the same in osx 10.12.6

bala223344 avatar Oct 25 '18 06:10 bala223344

I am suffering the same issue.

"canvas": "^2.0.1", "node-gyp": "^3.8.0", "chartjs-node": "^1.7.1", OS: Windows Node version: 8.9.4

Is this repo alive or was it abandoned? I see there was a time since last commit

ghost avatar Nov 06 '18 16:11 ghost

Also getting this same issue on Windows with any version of chartjs-node other than alpha2. Is there any fix for this?

thofnar avatar Nov 13 '18 00:11 thofnar

@tudorific the only way I was able to fix it was to downgrade canvas to a 1.6.x version. It is not working with canvas 2.x versions

(gdeliaesgine is my account at work but I answered you from home, using another user hehe)

gndelia avatar Nov 13 '18 02:11 gndelia

@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! :)

thofnar avatar Nov 15 '18 04:11 thofnar

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?

trysheepy avatar Feb 22 '19 16:02 trysheepy