`troubles integrating external modules in nuxt application`

Just starting with nuxt and incorporating it with vuetify. My aim was to integrate a Google Places Autocomplete feature, so I stumbled upon this: vuetify-google-autocomplete. It seemed simple enough to implement. But turns out it's not that straightforward.

I closely followed the documentation provided.

Created a file named google-autocomplete.js in the plugins directory:

import Vue from 'vue'
import VuetifyGoogleAutocomplete from 'vuetify-google-autocomplete'

Vue.use(VuetifyGoogleAutocomplete, {
  apiKey: 'MY_KEY'
})

In the nuxt.config.js, I added it like this:

plugins: ['@/plugins/vuetify', '@/plugins/google-autocomplete'],

Lastly, in my .vue file, I included:

<template>
  <vuetify-google-autocomplete
    id="map"
    append-icon="search"
    disabled="true"
    placeholder="Start typing"
    @placechanged="getAddressData"
  ></vuetify-google-autocomplete>
</teamplate>

In the script section, I defined a test method:

methods: {
  getAddressData: (addressData, placeResultData, id) => {
    console.log(addressData, placeResultData, id)
  }
}

The outcome? Everything is a mess! :D I'm encountering:

SyntaxError
Unexpected identifier
Missing stack frames
...etc...

Even tweaking the nuxt.config.js and setting the plugin ssr to false didn't prevent the failures, albeit the page loads but numerous issues arise with vuetify components not initializing.

Trying to grasp the right approach in employing these plugins/components within a nuxt project. Any insights are appreciated. Thanks

Answer №1

To properly integrate vuetify-google-autocomplete, it is recommended to include the transpile build option in your configuration. This is necessary due to the ES6 module usage within the plugin. For more detailed information, please refer to the ES6 plugins guide.

Ensure your nuxt.config.js includes the following:

export default {
  build: {
    transpile: ['google-autocomplete']
  },
  plugins: [
    '@/plugins/vuetify',
    '@/plugins/google-autocomplete'
  ]
}

Answer №2

Another helpful tip is if you encounter this issue when developing your own plugin that relies on an external package. Instead of creating a regular plugin, consider creating a Nuxt module. By doing this, you can easily include the plugin code and transpile settings in one step, eliminating the need to manually add them (and risk potentially forgetting) to nuxt.config.js

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Comparison between Mobile Phone's innerWidth and innerHeight Versus Resolution

My test phone, the Galaxy S3 Mini, has a resolution of 800x480 according to its specs. Strangely, when I run the following code in my HTML game: window.innerWidth window.innerHeight The width appears as 533 and the height as 295. I recently discovered ...

Trigger JavaScript function once all Ajax requests have completed

Seeking assistance with troubleshooting JavaScript code that is not functioning as expected. The Application sends file names to the server via Ajax calls for processing, but I need to update the database once all imports are complete. The problem arises ...

The form submission has been cancelled as the form connection is not active - Utilizing VueJs within laravel 8

I am trying to troubleshoot a response issue using the Google inspect tool. Despite checking Network>>XHR, I can't find any response. However, in the console, I saw the message "Form submission canceled because the form is not connected". The sc ...

Using Vue JS, can I include a route parameter (:id) in an i18N translation?

Consider this sample Vue JS template: <template> <b-container> <b-row> <b-col> <div> {{$t("competence.*web-developer*.title1")}} </div> </b-col> </b ...

Steps to automatically make jest mocked functions throw an error:

When using jest-mock-extended to create a mock like this: export interface SomeClient { someFunction(): number; someOtherFunction(): number; } const mockClient = mock<SomeClient>(); mockClient.someFunction.mockImplementation(() => 1); The d ...

Ways to clearly establish the concept of "a"

module.exports.getData = function (id) { const userData = require("./data/Users.json"); if (userData.find(user => user.uid === id)) { return user.name; } else return "User"; } I'm trying to display the name of a user, but the consol ...

Ways to adjust vue-loader in vue-cli for updating transformAssetsUrl

Currently, I am utilizing vue-cli version 3.0.1. I am interested in modifying the transformAssetsUrl setting, however, I am uncertain about the correct method to achieve this. () I am seeking guidance on the appropriate configuration for the chainWebpack ...

Tips on accessing close autoComplete/TextField title in AppBar

Looking to add a search bar and login button in the AppBar, where the search Bar is positioned close to the title. The desired order for the AppBar components should be as follows: Title SearchBox LoginButton How can this be achieved? Below is th ...

Animating an image into a Vue.js div

Is it possible to create a dynamic image animation using Vue.js? I am looking to create an interactive "Add to Cart" experience where when a user clicks on the button, the product's image smoothly glides over to the shopping cart icon before fading a ...

Obtain the identifier of a div within nested HTML components by utilizing jQuery

How do I retrieve the id of the first div with the class: post, which is "367", using jquery in the given HTML code: <div id="own-posts"> <span class="title">Me</span> <div class="posts_container"> <div class="post"& ...

Nesting maps in JavaScript is a powerful way to transform

I'm in the process of developing a budgeting app using React and JavaScript. At the moment, I have successfully generated a table displaying various costs. Name Budget Used $ Used % Available Food 300 300 100 0 Streaming services 600 600 100 ...

Absolute file path reference in Node.js

I'm working on a Node.js project using WebStorm IDE. Here's the structure of my project: The root folder is named "root" and inside are 2 folders: "main" and "typings". The "main" folder has a file called "foo.ts", while the "typings" folder co ...

Error: Attempting to access a property of an undefined object using method chaining

I encountered an error of property undefined with the code below. I'm not sure what's causing it. I checked by doing a console.log(navList) in the render and it does have a value. Even after adding if(!navList) return null, I still get the same e ...

Can I send an array of JavaScript classes to an MVC controller?

I'm struggling to pass an array of services to my controller. I've experimented with different methods, like serializing the data before sending it to the controller, serializing each service individually, and converting the controller parameter ...

Issue with importing in VueJS/TypeScript when using gRPC-Web

I have developed a straightforward VueJS application and am currently grappling with incorporating an example for file upload functionality. The proto file I am utilizing is as follows: syntax = "proto3"; message File { bytes content = 1; } ...

Triggering onClick without interfering with its populated variable

I'd like to add the following code snippet to my document: $('#myDiv).append("<div id='myDiv2' onclick="+extElementConfig.onClickDo+">Do</div>"); The code above uses an object with properties to populate the onClick attrib ...

Retrieve information from a website and transfer it to a Google spreadsheet

Despite the wealth of information on this topic, I have yet to find a solution that works for me. My goal is to transfer variables obtained from another website to Google Spreadsheet. These are the variables: var a = parseInt($('table.thinline:eq(4) ...

Adjust the top margin of a div to match the height of the screen within an iframe, ensuring cross-browser

Trying to adjust the margin-top of a div to 100% of screen height within an iframe seems to be causing issues with jQuery, as it either returns 0 or inaccurate values. While CSS3's 100vh can work as an alternative, it may not be supported in older an ...

Incorporating live text into a tag while arranging items by price in both ascending and descending order

I recently added a button to my online shop that allows users to sort products by price, even though I don't fully understand the underlying JavaScript code. I want to enhance this button by updating the text to indicate whether the sorting order is ...

Assign a temporary value to the Select component in Material UI version 1.0.0-beta.24

I am currently working on a test project using Material UI v1.0.0-beta.24, and I have noticed that the "Dropdown" menus behave differently compared to the previous version. What I am trying to achieve is setting up a placeholder in the Select component. P ...