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.js (SSR) #36

Open
2 of 3 tasks
florian-lefebvre opened this issue Feb 17, 2021 · 2 comments
Open
2 of 3 tasks

Doesn't work in Nuxt.js (SSR) #36

florian-lefebvre opened this issue Feb 17, 2021 · 2 comments

Comments

@florian-lefebvre
Copy link

Please check all that apply

  • visual bug
  • functional bug
  • able to consistently reproduce

Expected Behavior

Importing Flagpack as a plugin should work.

Current Behavior

I get an error: Unexpected token '<'.

Possible Solution

This might be related with the SSR mode

Steps to Reproduce

  1. Create a nuxt project and select SSR mode, Node.js hosting
  2. yarn add vue-flagpack
  3. create plugins/vue-flagpack.js and paste Method A from the docs
  4. Add it in the plugins array in nuxt.config.js like: plugins: ["~/plugins/vue-flagpack.js"]

Screenshots

image

Logs

See screenshot.

Context

I'm trying to add flags to a lang switcher, based on @nuxtjs/i18n.

Your Environment

  • Version used: "vue-flagpack": "^1.0.1"
  • Browser Name and version: Opera GX (Opera 73)
  • Operating System and version (desktop or mobile): Windows 10 x64
  • Nuxt: "nuxt": "^2.14.12",
  • Link to your project: Private Gitlab repo
@daoneandonly daoneandonly transferred this issue from Yummygum/flagpack-core Mar 3, 2021
@jdddog
Copy link

jdddog commented Jun 26, 2021

I found that it works if you transpile both flagpack-core and vue-flagpack, you do this by adding the following to nuxt.config.js:

build: {
    transpile: ['flagpack-core', 'vue-flagpack']
  }

I think it might be because flagpack-core is an es6 module and Nuxt expects something else?

You also need to wrap Flag in <client-only> or set the plugin mode parameter to 'client' .

@avrtau
Copy link

avrtau commented Sep 22, 2021

@jdddog Looks like setting mode: 'client' does the trick without the need for setting the transpile options

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