vmpowerio / chartjs-node

Create Chart.js Charts Server-side
http://chartjs-demo.vmpower.io
MIT License
226 stars 51 forks source link

error when using node-canvas alpha.8 #42

Open pedall opened 6 years ago

pedall commented 6 years ago

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?

nollybear commented 6 years ago

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.

djaoka commented 6 years ago

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

mjlocke0529 commented 6 years ago

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

Vishallimgire commented 6 years ago

which platform Windows or Linux

Vishallimgire commented 6 years ago

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)
bala223344 commented 6 years ago

still not resolved :(

I am getting the same in osx 10.12.6

ghost commented 5 years ago

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

thofnar commented 5 years ago

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

gndelia commented 5 years ago

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

thofnar commented 5 years ago

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

trysheepy commented 5 years ago

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?