最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - Can't generate Nuxt website with @googlemapsjs-api-loader - Stack Overflow

matteradmin6PV0评论

I am using @googlemaps/js-api-loader in my Nuxt 3 website. Everything works fine in local development, but when I try to build the project with nuxt generate (no matter if locally or on Vercel) I'm getting following error:

[nuxt] [request error] Named export 'Loader' not found. The requested module 'file:///path/to/website/node_modules/@googlemaps/js-api-loader/dist/index.umd.js' 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:

The important part of loading script looks like this:

import { Loader } from '@googlemaps/js-api-loader';

const loader = new Loader({
    apiKey: config.googleMapsApiKey,
    version: 'weekly',
});

onMounted(async() => {
    await loader
        .load()

        ...

so I tried to import this package differently, e.g.:

import * as gmaps from '@googlemaps/js-api-loader';
const { Loader } = gmaps;

and the previous error disappeared, but now I'm getting

[Vue warn]: Unhandled error during execution of setup function
  at <DynamicLocations class="contact__map" locations= [
  {
    id: 1,

...


[nuxt] [request error] gmaps.Loader is not a constructor
  at setup (./.nuxt/prerender/chunks/app/server.mjs:5536:20)  
  at _sfc_main$t.setup (./.nuxt/prerender/chunks/app/server.mjs:5582:25)  
  at callWithErrorHandling (./.nuxt/prerender/chunks/renderer.mjs:2654:23)  
  at setupStatefulComponent (./.nuxt/prerender/chunks/renderer.mjs:9548:30)  
  at setupComponent (./.nuxt/prerender/chunks/renderer.mjs:9503:12)  
  at renderComponentVNode (./.nuxt/prerender/chunks/renderer.mjs:12068:17)  
  at Object.ssrRenderComponent (./.nuxt/prerender/chunks/renderer.mjs:12504:12)  
  at ./.nuxt/prerender/chunks/app/server.mjs:5628:36  
  at renderComponentSubTree (./.nuxt/prerender/chunks/renderer.mjs:12149:13)  
  at renderComponentVNode (./.nuxt/prerender/chunks/renderer.mjs:12084:16)

I also can't import package by default export. Do you have any ideas what's going on and how can I fix this?

I am using @googlemaps/js-api-loader in my Nuxt 3 website. Everything works fine in local development, but when I try to build the project with nuxt generate (no matter if locally or on Vercel) I'm getting following error:

[nuxt] [request error] Named export 'Loader' not found. The requested module 'file:///path/to/website/node_modules/@googlemaps/js-api-loader/dist/index.umd.js' 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:

The important part of loading script looks like this:

import { Loader } from '@googlemaps/js-api-loader';

const loader = new Loader({
    apiKey: config.googleMapsApiKey,
    version: 'weekly',
});

onMounted(async() => {
    await loader
        .load()

        ...

so I tried to import this package differently, e.g.:

import * as gmaps from '@googlemaps/js-api-loader';
const { Loader } = gmaps;

and the previous error disappeared, but now I'm getting

[Vue warn]: Unhandled error during execution of setup function
  at <DynamicLocations class="contact__map" locations= [
  {
    id: 1,

...


[nuxt] [request error] gmaps.Loader is not a constructor
  at setup (./.nuxt/prerender/chunks/app/server.mjs:5536:20)  
  at _sfc_main$t.setup (./.nuxt/prerender/chunks/app/server.mjs:5582:25)  
  at callWithErrorHandling (./.nuxt/prerender/chunks/renderer.mjs:2654:23)  
  at setupStatefulComponent (./.nuxt/prerender/chunks/renderer.mjs:9548:30)  
  at setupComponent (./.nuxt/prerender/chunks/renderer.mjs:9503:12)  
  at renderComponentVNode (./.nuxt/prerender/chunks/renderer.mjs:12068:17)  
  at Object.ssrRenderComponent (./.nuxt/prerender/chunks/renderer.mjs:12504:12)  
  at ./.nuxt/prerender/chunks/app/server.mjs:5628:36  
  at renderComponentSubTree (./.nuxt/prerender/chunks/renderer.mjs:12149:13)  
  at renderComponentVNode (./.nuxt/prerender/chunks/renderer.mjs:12084:16)

I also can't import package by default export. Do you have any ideas what's going on and how can I fix this?

Share Improve this question edited Jun 12, 2022 at 13:09 Matthew asked Jun 12, 2022 at 13:02 MatthewMatthew 5192 silver badges14 bronze badges 1
  • 1 Importing the entire library worked for me, which of course is not ideal. I opened an issue on GH. github./googlemaps/js-api-loader/issues/692 – braitsch Commented Sep 27, 2022 at 18:39
Add a ment  | 

1 Answer 1

Reset to default 7

I found a documentation page related to this problem and there is the following information:

If you encounter these errors, the issue is almost certainly with the upstream library. They need to fix their library to support being imported by Node.

Although they provide a solution to get rid of errors by adding the package to build.transpile:

 build: {
     transpile: ['@googlemaps/js-api-loader'],
 },

It worked for me

Post a comment

comment list (0)

  1. No comments so far