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 in nextTick: "ReferenceError: getComputedStyle is not defined" #32

Closed
4ndre4s opened this issue Aug 8, 2019 · 12 comments
Closed

Comments

@4ndre4s
Copy link

4ndre4s commented Aug 8, 2019

I use the component in a Nuxt.js Application, but I get an error.

This is how the it gets rendered:
grafik

Error:
grafik

Code:
grafik

@4ndre4s 4ndre4s closed this as completed Aug 12, 2019
@astagi
Copy link

astagi commented Mar 23, 2020

Hi @4ndre4s how did you fix this issue? I got the same error with Nuxt!

@4ndre4s
Copy link
Author

4ndre4s commented Mar 23, 2020

Hi, I also used nuxt. Actually I could not fix it :(

@astagi
Copy link

astagi commented Mar 23, 2020

@4ndre4s I found the root of the problem, you need to wrap the editor around

<client-only placeholder="Loading...">
  <prism-editor :code="code" language="js" :line-numbers="true" />
</client-only>

The error disappears from console log but the graphical issue remains. Maybe something related to the default css of Nuxt, I'll investigate further :)

Thanks for the quick reply!

@astagi
Copy link

astagi commented Mar 23, 2020

Ok @4ndre4s I just fixed the second problem. We need to import VuePrismEditor.css as well to get the flex box for correctly displaying lines and code.

import 'prismjs'
import 'prismjs/themes/prism-tomorrow.css'
import 'vue-prism-editor/dist/VuePrismEditor.css'

import PrismEditor from 'vue-prism-editor'

It works great!

@astagi
Copy link

astagi commented Mar 23, 2020

Looks like there's also a PR open to fix this problem in documentation :) #36

@4ndre4s
Copy link
Author

4ndre4s commented Mar 23, 2020

Thank you!

@astagi
Copy link

astagi commented Mar 23, 2020

YW

@koca
Copy link
Owner

koca commented Mar 26, 2020

Oh i should also add a note for nuxt. Thanks guys!

@jordib123
Copy link

jordib123 commented Dec 21, 2021

I have the same problem. However, the vue-prism-editor package only contains "prismeditor.min.css" and no "VuePrismEditor.css"... I am using version 1.3.0.

TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

Edit: It looks like it only happens for php in
return highlight(this.code, languages.php)
Js, Ruby, Python, C#, ... works without issues.

@Fennec-hub
Copy link

@jordib123 take a look here #131, especially if you are using dynamic import.

@jordib123
Copy link

@Fennec-hub It looked like using php with Prism required an extra import besides prism-php

import "prismjs/components/prism-markup-templating.js";

@nicholasanthonys
Copy link

@4ndre4s did you manage to solve the problem ?

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