heatmap.js icon indicating copy to clipboard operation
heatmap.js copied to clipboard

Cannot assign to read only property 'data' of object

Open SVPA-CharlieSantos opened this issue 8 years ago • 15 comments

When using heatmap.js on certain browsers, this error Cannot assign to read only property 'data' of object shows up. screen shot 2016-09-01 at 11 18 47 am

I'm able to reproduce on chromium that is packaged with electron version 1.3.3.

This seems to happen because the data property of ImageData object is being replaced directly in this part of the code. https://github.com/pa7/heatmap.js/blob/master/src/renderer/canvas2d.js#L280

data property seems to be read only on certain browser versions. To fix it, we need to delete this line because imgData and img.data points to the same reference. Any modifications you do to imgData is already reflected to img.data. I'll put up a PR soon.

SVPA-CharlieSantos avatar Sep 01 '16 18:09 SVPA-CharlieSantos

Same here. I found that problem occur only on prod env when all my scripts are bundled and "use strict" is on top of bundle.

kmlwlkwk avatar Feb 22 '17 20:02 kmlwlkwk

FYI – this fork worked for me https://github.com/santoscharlie/heatmap.js/blob/146116ac2f0249d501ec3767729b8429fc57ae3e/build/heatmap.js

jakob-e avatar May 02 '17 11:05 jakob-e

I'm facing the same issue using heatmapjs in my Angular application.

njifares avatar Aug 08 '19 12:08 njifares

facing same issue , react rollup babel

shmilyoo avatar Jun 30 '20 08:06 shmilyoo

The fork shared by jakob-e works for me too. I'm using rollup to bundle everything. This has been open for some time. That fork is not on npm. What should be done next?

subtext916 avatar Jul 06 '20 04:07 subtext916

The fork shared by jakob-e is behind master by 12 commits.

This branch is 1 commit ahead, 12 commits behind pa7:master.

ascandal avatar Jul 16 '20 23:07 ascandal

Is there any progress on this one? The fix removed img.data replacement due to the following issue seem to do the trick. We tested this in our environment (Angular 8)

Thanks

theusner-thing avatar Apr 23 '21 10:04 theusner-thing

Any suggestions on how to include this fix from package.json (eg. load the library from that fork) ?

EDIT: This seems to work: "heatmap.js": "https://github.com/ionata/heatmap.js.git" instead of "heatmap.js": "^2.0.5"

Cristy94 avatar Jul 07 '21 14:07 Cristy94

heatmap.js version / usage bug

heatmap.js v2.0.5

  1. import errors ❌

import HeatMap from '@/libs/heatmap.min.js';
// import '@/libs/heatmap.min.js';

const parentPage = document.getElementById('parentPage');
const heatMapObj = HeatMap.create({
    container: parentPage,
    radius: 30,
    maxOpacity: .5,
    minOpacity: 0,
    blur: .75
});

// import HeatMap from '@/libs/heatmap.min.js';
import '@/libs/heatmap.min.js';

const parentPage = document.getElementById('parentPage');
const heatMapObj = h337.create({
    container: parentPage,
    radius: 30,
    maxOpacity: .5,
    minOpacity: 0,
    blur: .75
});
  1. window.h337 ok ✅

const importScript = () => {
    if(!window.h337) {
        const script = document.createElement('script');
        script.src = '/libs/heatmap.min.js';
        const body = document.querySelector('body');
        body.appendChild(script);
    }
};

importScript();

const parentPage = document.getElementById('parentPage');
const heatMapObj = h337.create({
    container: parentPage,
    radius: 30,
    maxOpacity: .5,
    minOpacity: 0,
    blur: .75
});

xgqfrms avatar Dec 06 '21 08:12 xgqfrms

#344 pull request. Should be fixing this issue.

ridweng avatar Dec 22 '21 18:12 ridweng

so how can this problem be solved in version 2.0.5

iaaseihy avatar May 12 '22 02:05 iaaseihy

so how can this problem be solved in version 2.0.5

Remove line 527 "img.data = imgData", or in the min version, locate this and delete it. That worked for me.

ridweng avatar May 12 '22 11:05 ridweng

同样在这里。我发现当我所有的脚都被抓绑定并“use strict”位在抓绑定包之时,问题只发生在 prod env 上。

你好,请问有解决了吗

chen766 avatar Dec 26 '22 09:12 chen766

This project appears to be abandoned. For anyone else experiencing this issue and using leaflet - switching to 'leaflet.heat' was easy enough. https://www.npmjs.com/package/leaflet.heat

lobaak avatar Apr 05 '23 22:04 lobaak

If you are using NPM patch-package, you could use the attached patch file to correct this in 2.0.5 directly in node_modules as part of your build scripts.

heatmap.js+2.0.5.patch

Nexudus avatar Mar 06 '24 09:03 Nexudus