I'm trying to add Vue-Splide to my Nuxt project, after following the Vue-Splide documentation to install the plugin, and registering it as a Nuxt plugin I get the error Cannot use import statement outside a module
.
nuxt.config.js
buildDir: '../functions/nuxt',
build: {
publicPath: '/public/',
vendor: [''],
extractCSS: true,
babel: {
presets: [
'@babel/preset-env'
],
plugins: [
["@babel/plugin-transform-runtime"]
]
}
},
plugins: [
{ src: '~/plugins/splide.client.js', mode: "client" }
],
splide.client.js
import Vue from 'vue';
import VueSplide from '@splidejs/vue-splide';
import '@splidejs/splide/dist/css/themes/splide-default.min.css';
Vue.use(VueSplide);
template
<splide :options="{ rewind: true }" class="banner-container">
<splide-slide class="slide" v-for="slide in slides" :key="slide.id">
<img :src="slide.imagen" :alt="slide.tombre" />
</splide-slide>
</splide>
After transpiling Vue-Splide I now get the error window is not defined
, and the stacktrace shows it's happening on node_modules\@splidejs\splide\dist\js\splide.js
, I tried surrounding the splide tags with <client-only></client-only>
, but that didn't seem to work.
What else am I missing here?
Updating to include my dependencies
"dependencies": {
"@nuxtjs/firebase": "^7.6.1",
"@splidejs/vue-splide": "^0.3.5",
"firebase": "^8.9.1",
"isomorphic-fetch": "^3.0.0",
"nuxt": "^2.0.0"
},
"devDependencies": {
"@babel/plugin-transform-runtime": "^7.15.0",
"@babel/preset-env": "^7.15.6",
"@babel/runtime": "^7.15.4",
"@nuxtjs/tailwindcss": "^4.2.1",
"autoprefixer": "^10.4.0",
"babel-eslint": "^10.0.1",
"babel-plugin-module-resolver": "^4.1.0",
"eslint": "^4.19.1",
"eslint-friendly-formatter": "^4.0.1",
"eslint-loader": "^4.0.2",
"eslint-plugin-vue": "^7.19.1",
"firebase-tools": "^9.22.0",
"node-sass": "^6.0.1",
"postcss": "^8.3.11",
"sass-loader": "^12.3.0",
"tailwindcss": "^2.2.19"
}