Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

luca-dev's avatar

Uncaught SnytaxError: import not found: default. How do I fix that?

I'm new to Vue.js and this is my first project with it - it's a weather forecast page with multiple views for different forecasts but that's not the important part. I wrote a mixin that gets your location and puts it into a url that resolves into a JSON with forecast data. I found the use of a global mixin to be helpful because almost all of my components (would) use this mixin. But it seems as though the import needed for the mixin doesn't work - let me explain.

---- main.js ----

import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router/index'
import weathermixin from './components/mixins/weather.js'

createApp(App).mount('#app')`

---- weather.js ----

export default{
    data(){
        return{
            data: {
                weatherData: [{}]
            }
        }
    },
    methods: {
        async getCoordinates(onSuccess, onError){
            if(!navigator.geolocation){
                console.error("Couldn't get coordinates. Press F5 to try again");
            }
            else{
                navigator.geolocation.getCurrentPosition(onSuccess, onError);
            }
        },
        async onSuccess(){
            const {
                latitude,
                longitude
            } = position.coords;
            var userLat = latitude;
            var userLong = longitude;

            const response = await fetch(
                'https://api.open-meteo.com/v1/forecast?latitude=${userLat}&longitude=${userLong}&hourly=temperature_2m,weathercode&daily=weathercode,temperature_2m_max,temperature_2m_min&timezone=Europe%2FBerlin&current_weather=1'
              );
              const responseData = await response.json();
              this.weatherData = responseData;
        
              console.log(this.weatherData);
              return responseData;
        },
        onError(){
            alert("Something went wrong while fetching your coordinates! Press F5 to try again!");
        }
    }
}

I import/ use it in a component with $this.getCoordinates() but where does the syntax error come from? I looked it up and it seems like the right way to implement a global mixin. Why does it give me this error and how do I fix it? Thank you in advance.

Vue / Vite versions: vue: 3.2.37 vue-router: 4.1.2 vitejs/plugin-vue: 3.0.0 vite: 3.0.0

0 likes
6 replies
piljac1's avatar

You're missing a single quote after your mixin's path (where you import it).

1 like
luca-dev's avatar

@piljac1 it's not like that in the real code, I accidentally removed it while editing it on here. I'll fix it in the post though

piljac1's avatar

@luca-dev how do you register the mixin ? You show the import but not the registration.

1 like
piljac1's avatar

@luca-dev You're on Vue 3 and the link you provided is in Vue 2. In Vue 3, you should call the mixin method on the Vue instance and not statically like before. So where your createApp is, save it in a const app variable and then app.mixin(yourMixin);.

Note : it is suggested to use composables for reusable logic instead of mixins in Vue 3.

1 like
luca-dev's avatar

@piljac1 ahhhh okay, I get it now! I'll try that and I'll read the docs for composables. Thank you! :)

Please or to participate in this conversation.