-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Description
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
- Follow our Code of Conduct
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.