Skip to content

Conversation

Copy link

Copilot AI commented Oct 30, 2025

Build fails when @googlemaps/markerclusterer is not installed, even when the MarkerClusterer component is unused. Vite resolves top-level imports at build time, causing errors for missing optional peer dependencies.

Changes

  • ScriptGoogleMapsMarkerClusterer.vue: Convert static import to dynamic import pattern
    • Changed import { MarkerClusterer }import type { MarkerClusterer } (type-only import)
    • Added await import('@googlemaps/markerclusterer') inside component lifecycle (runtime import)

This follows the same pattern already used by PayPal components for optional dependencies.

Example

// Before - fails build without dependency installed
import { MarkerClusterer } from '@googlemaps/markerclusterer'
whenever(() => mapContext?.map.value, (map) => {
  markerClusterer.value = new MarkerClusterer({ map })
})

// After - only imports when component is used
import type { MarkerClusterer } from '@googlemaps/markerclusterer'
whenever(() => mapContext?.map.value, async (map) => {
  const { MarkerClusterer } = await import('@googlemaps/markerclusterer')
  markerClusterer.value = new MarkerClusterer({ map })
})

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • cdn.jsdelivr.net
    • Triggering command: node (vitest 1) (dns block)
  • code.jquery.com
    • Triggering command: node /home/REDACTED/work/scripts/scripts/node_modules/.bin/../nuxt/bin/nuxt.mjs build (dns block)
    • Triggering command: node (vitest 3) (dns block)
  • fonts.googleapis.com
    • Triggering command: node /home/REDACTED/work/scripts/scripts/node_modules/.bin/../nuxt/bin/nuxt.mjs generate client (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>@nuxt/scripts: MarkerClusterer import error when building - missing @googlemaps/markerclusterer dependency</issue_title>
<issue_description>### 🐛 The bug

When building the project with @nuxt/scripts@0.13.0, the build process fails with an error:

"MarkerClusterer" is not exported by "__vite-optional-peer-dep:@googlemaps/markerclusterer:@nuxt/scripts:false", imported by "node_modules/@nuxt/scripts/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue".

The build fails even though we're not using the GoogleMaps MarkerClusterer component in our project. The optional peer dependency should not cause a build failure.

🛠️ To reproduce

  1. Create a Nuxt 4 project with @nuxt/scripts@0.13.0 2. Do not install @googlemaps/markerclusterer as it's not used in the project 3. Run npm run build or bun run build

🌈 Expected behavior

Error: [nuxi] Nuxt Build Error: node_modules/@nuxt/scripts/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue (4:9): "MarkerClusterer" is not exported by "__vite-optional-peer-dep:@googlemaps/markerclusterer:@nuxt/scripts:false", imported by "node_modules/@nuxt/scripts/dist/runtime/components/GoogleMaps/ScriptGoogleMapsMarkerClusterer.vue".

ℹ️ Additional context

Environment:

  • @nuxt/scripts: 0.13.0
  • Nuxt: 4.2.0
  • Package manager: bun</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@vercel
Copy link

vercel bot commented Oct 30, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
scripts-docs Ready Ready Preview Comment Oct 30, 2025 5:38pm
scripts-playground Ready Ready Preview Comment Oct 30, 2025 5:38pm

Co-authored-by: harlan-zw <5326365+harlan-zw@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix MarkerClusterer import error in Nuxt build process Fix: Convert MarkerClusterer to dynamic import to support optional peer dependency Oct 30, 2025
Copilot AI requested a review from harlan-zw October 30, 2025 17:38
Copilot finished work on behalf of harlan-zw October 30, 2025 17:38
@harlan-zw harlan-zw changed the title Fix: Convert MarkerClusterer to dynamic import to support optional peer dependency fix: Convert MarkerClusterer to dynamic import to support optional peer dependency Oct 31, 2025
@harlan-zw harlan-zw marked this pull request as ready for review October 31, 2025 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@nuxt/scripts: MarkerClusterer import error when building - missing @googlemaps/markerclusterer dependency

2 participants