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

Usage with Nuxt #26

Open
jeffp123 opened this issue Nov 18, 2019 · 12 comments
Open

Usage with Nuxt #26

jeffp123 opened this issue Nov 18, 2019 · 12 comments

Comments

@jeffp123
Copy link

jeffp123 commented Nov 18, 2019

To use with Nuxt 2.10.0, I had to do the following to avoid "document is not defined":

Make a new file in plugins called vue-plotly.js and put this in it:

import Vue from 'vue';
import vPlotly from '@statnett/vue-plotly';

const VuePlotly = {
  install(Vue) {
    Vue.component('vue-plotly', vPlotly);
  },
};
Vue.use(VuePlotly);
export default VuePlotly;

And add this line to nuxt.config.js (or update plugins)

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

Then, you can use <vue-plotly/> anywhere without having to import it.


Prior to discovering this solution, I had wrapped my chart component in <client-only/>, and was loading that component like this:

components: {
    // See here: https://stackoverflow.com/a/50458090/107083
    graph: () => import('@/components/Graph.vue'),
  },

This also worked, but I would get a warning. The above way seems "more correct".

I'm curious if anybody wants to comment on pros/cons of either approach, but am mainly putting this here in case others are stuck with this issue.

@jeffp123
Copy link
Author

jeffp123 commented Nov 18, 2019

As for reporting this as an "issue", it would be good if vue-plotly included this information in the readme or documentation. I would guess that this is a common use-case is with Nuxt and documentation that demonstrates Nuxt-compatibility would be useful.

@jeffp123
Copy link
Author

It appears that I still need to wrap <vue-plotly/> in <client-only/> to avoid the warning "The client-side rendered virtual DOM tree is not matching server-rendered content."

I'm not 100% if that is correct, but seems to make sense.

@SumNeuron
Copy link

@chaimpeck You do not have to wrap in client-only... only if you are trying to bind data server side. If you async data on mount youll be fine. Anyway, statnett doesn't seem too keen on helping with issues :P

@ghost
Copy link

ghost commented Dec 19, 2019

@chaimpeck You do not have to wrap in client-only... only if you are trying to bind data server side. If you async data on mount youll be fine. Anyway, statnett doesn't seem too keen on helping with issues :P

I'm not pulling from an external data source (yet anyway, just getting the syntax worked out). I did have to add <client only> as mentioned and plugins: [{ src: '~plugins/vue-plotly', mode: 'client' }], in order to get this to work and avoid the errors.

Since I am a neophyte and you appear to have more background I would appreciate feedback, if you have it, on whether this would be the expected behavior and if I am missing something?

@MiltonCobo
Copy link

Hello, i'm trying to use vue-plotly in a nuxt project. I followed your advice, created the vue-plotly.js file at plugins, and add to the nuxt.config.js file, but still i get the error
---Uncaught TypeError: Cannot read property 'Config' of vue-plotly.umd.js?04d1:95906 undefined---
Any new information?
Thanks

@jeffp123
Copy link
Author

Hrm, I don't have any more info on this. The above worked for me, but I haven't gone back to it in a while. Maybe a different version?

@MiltonCobo
Copy link

MiltonCobo commented Apr 19, 2020 via email

@jeffp123
Copy link
Author

hrm, I don't know why that would be, sorry

@umardraz
Copy link

Hello I am trying to use this with nuxtjs and getting this error

ERROR  Failed to compile with 2 errors 
This dependency was not found:  

* fs in ./node_modules/image-size/lib/index.js, ./node_modules/image-size/lib/types/tiff.js  
* To install it, you can run: npm install --save fs  
* Waiting for file changes

Would you please help me

@jeffp123
Copy link
Author

@umardraz It looks like you need to install fs, right?

@umardraz
Copy link

No it was not fs issue. I am susing webpack so I simply did this and it worked

config.node = {
    fs: 'empty'
}

@amoose136
Copy link

amoose136 commented Oct 5, 2021

No it was not fs issue. I am susing webpack so I simply did this and it worked

config.node = {
    fs: 'empty'
}

Where did you add that snippet? I am getting the same error.

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

5 participants