Search code examples
javascriptvue.jsjsfiddle

Unexpected token import - jsfiddle


I am trying to make the toastr library work in jsfiddle but I keep getting this error: Uncaught SyntaxError: Unexpected token import

This is my jsfiddle: https://jsfiddle.net/50wL7mdz/77255/

This is my code:

import VueToastr from '@deveodk/vue-toastr';
Vue.use(VueToastr, {
    defaultPosition: 'toast-bottom-left',
    defaultType: 'info',
    defaultTimeout: 1000
});
new Vue({
  el: '#app',
  data: {    
  },
  created(){
    this.$toastr('success', 'it works!', 'Yeahh');
  },
  methods: {          
  }
})

and this is the library reference: https://github.com/Deveodk/vue-toastr

Does import keyword not work in jsfiddle?


Solution

  • Imports does not work on JSFIDDLE. You need to install the package and refer using import, which is not supported. Instead you can do this,

    You can refer the library using external url,

    https://unpkg.com/vue-toastr-2@0.0.8/dist/vue-toastr-2.js
    https://unpkg.com/vue-toastr-2/dist/vue-toastr-2.min.css
    

    DEMO