question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ValidationError: Classes can only be applied to DOM elements, not components

See original GitHub issue

In my setup I use the rollup-plugin-svelte and for the client-side routing I tried the svero svelte router. Apparently, passing a class attribute to component should be possible, see kazzkiq/svero#13 and kazzkiq/svero@26b48a6

When I try to use it as in the example from kazzkiq/svero#45 I got following compile error:

rollup v1.27.0
bundles src/main.js → public/bundle.js...
[!] (plugin svelte) ValidationError: Classes can only be applied to DOM elements, not components
src/components/Navbar.svelte
38:         <ul class="navbar-nav mx-auto">
39:             <li class="nav-item mx-2">
40:                 <Link href={MAIN_PATH} class:active={path.includes(MAIN_PATH)}>
                                           ^
41:                     Feedback
42:                 </Link>
ValidationError: Classes can only be applied to DOM elements, not components

I do not think this is actually related to svero but probably to the rollup-plugin-svelte

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
alexdilleycommented, Dec 5, 2019

Sorry, yes, this line allows class to be provided as a prop. You can’t use it in directive form though, so it will need to be:

class="{path.includes(MAIN_PATH) ? 'active' : ''}"
0reactions
karlitoscommented, Dec 5, 2019

Thanks for clarification 👍 closing now

Read more comments on GitHub >

github_iconTop Results From Across the Web

Adding classes to components in SvelteKit - Stack Overflow
However, you cannot use the Svelte class:name directive on IconButton as that type of directive is indeed restricted to DOM elements.
Read more >
Workaround for "Transitions can only be applied to DOM ...
I have a small carousel of pullquotes. When a pullquote changes, I want to cross-fade from the current quote to the new quote....
Read more >
constructor - JavaScript - MDN Web Docs - Mozilla
The ValidationError class doesn't need an explicit constructor, because it doesn't need to do any custom initialization. The default constructor ...
Read more >
Element: <oj-input-text> - Oracle
See validate method on the sub-classes for details. Note: JET validation is designed to catch user input errors, and not invalid data passed ......
Read more >
Validation · Bootstrap v5.0
Bootstrap scopes the :invalid and :valid styles to parent .was-validated class, usually applied to the <form> . Otherwise, any required field without a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found