0

When running gridsome build I get window is not defined. Anyone has an example of making vue2-leaflet work with the client only option for gridsome?

2 Answers2

2

Wrap your component inside template with <ClientOnly> tag, more info in my other answer

Hermesis
  • 166
  • 7
  • Thanks [@Hermesis](https://stackoverflow.com/users/12584011/hermesis), wrapping the template with `` was part of the solution. This is what worked for me in the end: [https://github.com/gridsome/gridsome/issues/646](https://github.com/gridsome/gridsome/issues/646) – Vasilis Tsirimokos Sep 06 '20 at 20:45
0

I've been struggling with the same problem (but with other libraries) and the only solution i've found was to copy the package into src/. Something like :

cp -a node_modules/package-giving-me-headaches src/plugins

and

// main.js
import PackageGivingMeHeadaches from "~/plugins/package-giving-me-headaches"

Depending on the package, you may need to target a specific entry point :

// main.js
import PackageGivingMeHeadaches from "~/plugins/package-giving-me-headaches/src" 

You know you need to do that when Gridsome tells you :

"export 'default' (imported as 'PackageGivingMeHeadaches') was not found in '~/plugins/package-giving-me-headaches'

Edit : Yes, i know its not ideal and ugly, but i don't have time to fight for it.

HPDL
  • 11
  • 1
  • Thanks [@HPDL](https://stackoverflow.com/users/11790609/hpdl) for taking the time to propose a solution. I wouldn't downvote it but I also don't think it's an ideal solution. – Vasilis Tsirimokos Jul 23 '19 at 19:15