8

I am trying to use vue-agile carousel, I can install and get it to run without any issues right after i install it, i am using NUXT, but after restarting my server i keep getting this error and can not find any solution for it

<template>
  <div>
    <agile>
      <div class="slide">
        <img src="/img/img2.jpg" alt="" />
      </div>
      <div class="slide">
        <img src="/img/img1.jpg" alt="" />
      </div>
    </agile>
  </div>
</template>
<script >
import { VueAgile } from "vue-agile";
export default {
  name: "",
  layout: "",
  middleware: [],
  data() {
    return {};
  },
  components: {
    agile: VueAgile,
  },
  
};
</script>

enter image description here

enter image description here

1
  • Did you ever find a solution to this? Commented Jan 5, 2021 at 18:56

5 Answers 5

6

Did you checked the documentation about how to use this plugin in Nuxt instead of a regular Vue?

plugins/vue-agile.js

import Vue from 'vue'
import VueAgile from 'vue-agile'

Vue.use(VueAgile)

nuxt.config.js

export default {
    plugins: ['~/plugins/vue-agile', mode: 'client']
}

To use component without SSR use the client-only component:

<client-only placeholder="Loading...">
    <agile>...</agile>
</client-only>

EDIT: Add Shreerang's suggestion (comment below).

Sign up to request clarification or add additional context in comments.

4 Comments

I get the same error message. and added a new pic to my question
That warning in the new screenshot is because you are using Typescript, and that node_module is not ready for I guess, but I don't think that is a problem. I found a possible solution, other people reported that maybe this can happen when you update the Node version but you don't update your node_modules after that, so maybe you can try this:rm -rf node_modules && npm install in your Nuxt root folder. Let me know if it helps, it sounds like magical I know haha.
Nope, still the same, and it s not just this modules, even the one I use to used before giving me the same error
can also be used here right? inside if(process.client) {...}
4

from official Nuxt.js docs, they said.

If you get an Cannot use import statement outside a module error, you may need to add your package to the build > transpile option in nuxt.config.js for webpack loader to make your plugin available.

Example

module.exports = {
  build: {
    transpile: ['vue-agile']
  }
}

Comments

3

Sergio's answer above is mostly accurate, but needs a small tweek.

The nuxt.config.json config needs the following update. No build config is required.

plugins: [
    { src: '~/plugins/vue-agile', mode: 'client' }
]

1 Comment

Sure, the error seems to be in the server side, I changed my answer to include this. Thanks!
2

You need to mark vue-agile to be transpiled in order to work on the server part (SSR).

nuxt.config.js :

...
  build: {
    transpile: [/vue-agile/]

  }
...

Comments

0

Add type="module" in your script tag

<script type="module">
import { VueAgile } from "vue-agile";
export default {
  name: "",
  layout: "",
  middleware: [],
  data() {
    return {};
  },
  components: {
    agile: VueAgile,
  },
  
};
</script>

1 Comment

Same error , i think I tried that before. this is very frustrating.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.