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

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

Open
miketromba opened this issue Jan 7, 2020 · 5 comments
Open

Comments

@miketromba
Copy link

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 },
}
@Ben2146053
Copy link

Do we have any update on this?

@WouterFlorijn
Copy link
Owner

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.

@DanielAlcaraz
Copy link

DanielAlcaraz commented Jun 10, 2020

Maybe is related to this:
nuxt/nuxt#924 (comment)

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

@guastallaigor
Copy link

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.

@shot-codes
Copy link

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?

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

6 participants