Nuxt.js: Error importing npm vue component

Created on 3 Feb 2017  ·  16Comments  ·  Source: nuxt/nuxt.js

Hello!

I'm trying to integrate google maps plugin (https://www.npmjs.com/package/vue2-google-maps), but then i'm trying to import it in my plugin file it sends me an error

Alt text

I've already implemented this module in another project (without Nuxt), and it works fine

This question is available on Nuxt.js community (#c170)
question

Most helpful comment

@pdll can you try:

import Vue from 'vue'

if (process.BROWSER_BUILD) {
  const googleMaps = require('vue2-google-maps')
  Vue.use(googleMaps({ /* options */ }))
}

All 16 comments

Hi, can you provide us a screenshot of you plugin?

Alt text

Nope, still the same error

and yes,
Module build failed: SyntaxError: 'import' and 'export' may only appear at the top level (4:2)

@pdll can you try:

import Vue from 'vue'

if (process.BROWSER_BUILD) {
  const googleMaps = require('vue2-google-maps')
  Vue.use(googleMaps({ /* options */ }))
}

Yes, seems like this one works for me, thank you.

Hi @Atinux

Me again 😁
What i'm missing here? I got Uncaught TypeError: googleMaps is not a function

Nevermind, i found the problem, thank you 😁

Vue-google-map and Vue2-google-map not working with NUXT got below error

Nuxt.js Error:
ReferenceError: window is not defined
at Object. (~/vue-google-maps/index.js:1:6551)
at e (~/vue-google-maps/index.js:1:321)
at Object. (~/vue-google-maps/index.js:1:689)
at e (~/vue-google-maps/index.js:1:321)
at t.__esModule.default (~/vue-google-maps/index.js:1:394)
at 6.server-bundle.js:4024:382
at exports.modules.917.r.(anonymous function).exports (~/vue-google-maps/index.js:1:15)
at Object.917 (~/vue-google-maps/index.js:1:204)
at __webpack_require__ (webpack:/webpack/bootstrap 42a7e2d4e5d34af8ad2b:25:0)
at Object.349 (6.server-bundle.js:310:74)

Same error. not fixed.

hi @Cengkaruk,

How did you solve that problem? I am facing the same...

in my nuxt.config.js I have

plugins: [
 { src: '~plugins/maps.js', ssr: false }
  ],

In plugins/maps.js I have

import Vue from 'vue'

if (process.browser) {
  const googleMaps = require('vue2-google-maps')
  Vue.use(googleMaps({
    key: process.env.googleMapsKey,
    libraries: 'places'
  }))
}

This gives the exception Uncaught TypeError: googleMaps is not a function on Vue.us(googleMaps

This seems a good candidate for nuxt: https://github.com/xkjyeah/vue-google-maps

There is even an official nuxt section in their README for nuxt integration. But i can confirm not fully working too. (Because they are exporting non transpiled .vue files)

@pi0 does that solution on the github page work for you? It is giving me problems...

@osudio-erik No it doesn't (reported from one of my friends) :(

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jaredreich picture jaredreich  ·  3Comments

bimohxh picture bimohxh  ·  3Comments

nassimbenkirane picture nassimbenkirane  ·  3Comments

o-alexandrov picture o-alexandrov  ·  3Comments

vadimsg picture vadimsg  ·  3Comments