Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in nuxt: Cannot use import statement outside a module #31

Closed
vervelover opened this issue Oct 13, 2021 · 5 comments
Closed

Comments

@vervelover
Copy link

Hi,

I'm trying to use your slider within a nuxt.js project, but I always get this error:

'Cannot use import statement outside a module'

Composition API is installed and working, can you try the latest stable version of nuxt and see if your instructions still work?

Thank you for your help,
Alessio

@SchneiderOr
Copy link

Same here, nuxt3, module throwing the same error

@SchneiderOr
Copy link

Managed to make it work using nuxt3, if you you nuxt3 and need any further help let me know and ill share my solution

@vervelover
Copy link
Author

Hi Schneider,
I'm currently on nuxt v2 but already using some components/features from v3, so yes any help would be much appreciated, thank you!

@SchneiderOr
Copy link

Hi Schneider, I'm currently on nuxt v2 but already using some components/features from v3, so yes any help would be much appreciated, thank you!

Hey @vervelover
im attaching my component file & nuxt.config.ts/js file, im using nuxt3 + typescript so it might be deferred a little.

components/Slider.vue

<template>
  <SliderComponent v-model="currentValues" />
</template>

<script lang="ts">
import SliderComponent from "@vueform/slider";

export default defineComponent({
  components: {
    SliderComponent, // This is required in order to use the component in the template context.
  },
  setup(props) {
      // Your setup logic goes here
  },
});
</script>
<style src="@vueform/slider/themes/default.css"></style>
<style scoped>
 // custom css here
</style>

nuxt.config.ts

import { defineNuxtConfig } from "nuxt3";

export default defineNuxtConfig({
  build: {
    transpile: ["@vueform/slider"], // If you use nuxt you must transpile the module so it can be used universally 
  },
});

for me the caveat was the nuxt.config.ts, once i transpired it everything worked.

Hope it will work to you as well

@adamberecz
Copy link
Collaborator

Adding:

build: {
  transpile: ["@vueform/slider"], // If you use nuxt you must transpile the module so it can be used universally 
},

to Nuxt config should work in both versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants