Skip to content

Vite errors on import of @googlemaps/js-api-loader #15620

@apparchsysad

Description

@apparchsysad

Describe the bug

I'm trying to use the Google Maps api-loader library to inject the Google Maps api script into my sveltekit webapp. The library was installed in my project with "npm i @googlemaps/js-api-loader" and is invoked in my webapp code with "import { Loader } from '@googlemaps/js-api-loader';".

When I run "npm run dev", the procedure fails with the following error :

22:04:04 [vite] Error when evaluating SSR module /src/routes/+page.svelte: failed to import "@googlemaps/js-api-loader"
|- SyntaxError: [vite] Named export 'Loader' not found. The requested module '@googlemaps/js-api-loader' is a CommonJS module, which may not support all module.exports as named exports.

The message goes on to explain how I might try using a default export :

_The requested module '@googlemaps/js-api-loader' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:

import pkg from '@googlemaps/js-api-loader';
const {Loader} = pkg;_

But when I try this, the webapp itself fails telling me that the api-loader package doesn't provide a default export:

app.js:16 SyntaxError: The requested module '/node_modules/.vite/deps/@googlemaps_js-api-loader.js?v=5fcf71f8' does not provide an export named 'default'

Others have reported similar issues with 'npm run build' but as far as I can see I'm the only one with an 'npm run dev' problem

Reproduction

https://github.com/apparchsysad/test

Steps to reproduce

The test repository at https://github.com/apparchsysad/test was created as a skeleton webapp with the following npm commands:

npm create svelte@latest .
npm install
npm i @googlemaps/js-api-loader

The skeleton +page.svelte file was then modified to import the loader and display a Google map

System Info

System is a terminal session in VSCode on a Windows 11 PC

Used Package Manager

npm

Logs

No response

Validations

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions