vue-stack-grid icon indicating copy to clipboard operation
vue-stack-grid copied to clipboard

Error: "Cannot use import statement outside a module" ( Nuxt.js )

Open miketromba opened this issue 5 years ago • 5 comments
trafficstars

Getting this error when using Nuxt.js.

The component is wrapped in a client-only tag to avoid any SSR issues.

<client-only></client-only>

Error screenshot:

89a45a1dd4dad4dc50c44bc97d03fc28

Implementation:

In component

<Stack :monitor-images-loaded="true" :column-min-width="320" :gutter-width="8" :gutter-height="8">
        <StackItem v-for="i in 100" :key="i">
                <img src="https://i.imgur.com/0ui5ltX.jpg" />
        </StackItem>
</Stack>

Component registration

import { Stack, StackItem } from 'vue-stack-grid'
export default {
    components: { Stack, StackItem },
}

miketromba avatar Jan 07 '20 18:01 miketromba

Do we have any update on this?

Ben2146053 avatar Mar 21 '20 07:03 Ben2146053

I believe Nuxt SSR doesn't handle ES6 modules. I want to make this package transpile to CommonJS, but I'm currently very busy with my day job. If anyone wants to make a PR with Webpack/Babel configuration, I'll definitely look at it.

WouterFlorijn avatar Mar 26 '20 13:03 WouterFlorijn

Maybe is related to this: https://github.com/nuxt/nuxt.js/issues/924#issuecomment-309417199

I don't know if with the transpile option it can work: https://nuxtjs.org/api/configuration-build#transpile

DanielAlcaraz avatar Jun 10 '20 14:06 DanielAlcaraz

I think I have a workaroud. Instead of importing the Stack and StackItem components directly into your page/layout component, you create a Nuxt.js plugin:

plugins/vue-stack-grid.js

import Vue from 'vue'
import { Stack, StackItem } from 'vue-stack-grid'

Vue.component('Stack', Stack)
Vue.component('StackItem', StackItem)

And then, in your nuxt.config.js you import it, and set the mode: 'client'.

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

Seems to have worked for me at least.

guastallaigor avatar Jul 26 '20 00:07 guastallaigor

I was able to get the component imported by using @guastallaigor's workaround. However, I am seeing some odd behaviour:

Screenshot 2021-05-25 at 16 04 43

Any ideas of what to take a look at to debug?

shot-codes avatar May 25 '21 14:05 shot-codes