react-jvectormap icon indicating copy to clipboard operation
react-jvectormap copied to clipboard

Cannot set property 'vectorMap' of undefined

Open 0DevGuru0 opened this issue 6 years ago • 11 comments

i implemented the jvectormap on react ssr with webpack but i warned this error and i dont know why its happen: error:

node_modules\react-jvectormap\build\index.js:6504
                l.fn.vectorMap = function (l) {
                               ^
TypeError: Cannot set property 'vectorMap' of undefined

0DevGuru0 avatar Jul 09 '19 08:07 0DevGuru0

Hey @afsan007 I'll need more info in order to look it up

kadoshms avatar Jul 09 '19 08:07 kadoshms

@kadoshms I'm having the same problem... I'm using Next.js; if you load the page where the map is on the browser it renders fine, but if you load the page through the server - on a refresh, for example - the page crashes with the error @afsan007 posted.

I take a really quick look at the code and as far as I could understand, it depends on window to load the map... if I'm right, this is probably causing the problem with SSR :confused:

ghost avatar Aug 09 '19 20:08 ghost

https://stackoverflow.com/questions/53139884/next-js-disable-server-side-rendering-on-some-pages/53191080

janat08 avatar Nov 12 '19 13:11 janat08

I suspect rendering it dynamically causes issues with the map being drawn very small.

janat08 avatar Nov 12 '19 13:11 janat08

Anyway in which to redraw it after mounting, or something? I tried rendering it inside an empty div with fixed height and width that isn't dynamically loaded.

janat08 avatar Nov 12 '19 13:11 janat08

Same issue inside a Gatsby project. Any ideas?

maxscience avatar Dec 17 '19 11:12 maxscience

If you are using nextjs 👀 This may be useful, it works for me: https://github.com/vercel/next.js/issues/2940

/* file using VectorMap*/
const VectorMap = dynamic(
  () => import("react-jvectormap").then((m) => m.VectorMap),
  { ssr: false, }
);
/* ... */
<VectorMap />

fullsuper avatar Jun 20 '20 14:06 fullsuper

Has anybody found a fix yet?

iam-abbas avatar Sep 12 '20 07:09 iam-abbas

In webpack Import like this

https://www.npmjs.com/package/jvectormap-next window.jQuery = window.$ = require('jquery'); require('jvectormap-next')(window.$); $.fn.vectorMap('addMap', 'world_mill', require('jvectormap-content/world-mill')); $.fn.vectorMap('addMap', 'de_merc', require('jvectormap-content/de-merc')); $.fn.vectorMap('addMap', 'us_aea', require('jvectormap-content/us-aea'));

chirumist avatar Sep 30 '20 11:09 chirumist

Same issue inside a Gatsby project. Any ideas?

I am also using Gatsby, have you found a solution to it?

moaazassali avatar Jan 03 '21 22:01 moaazassali

Hey guys, thanks for reporting this. Since this project started as a side husstle for a specific POC project, I havn't covered SSR at the first place.

I will take a deepr look into it in the upcoming vesrions.

kadoshms avatar Oct 30 '21 11:10 kadoshms