Home » vue » Gridsome build fails when used with vue2-leaflet plugin

Gridsome build fails when used with vue2-leaflet plugin

Posted by: admin November 26, 2021 Leave a comment

Questions:

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?

Answers:

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

###

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.