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.

Svelte code is rejected because of adjacent elements

See original GitHub issue

Prettier 1.19.1 Playground link

--parser babel

Input:

<svelte:head>
    <title>Tic Tac Toe</title>
</svelte:head>

<h1>Tic Tac Toe</h1>

<button on:click={newGame}>New Game</button>

{#if message}
    <h2>{message}</h2>
{/if}

<Board {game} clickCell={(x, y) => (game = game.click(x, y))} />

<style>
  /* Styling goes here */
</style>
  
<script>
/* JavaScript goes here */
</script>




Output:

SyntaxError: Adjacent JSX elements must be wrapped in an enclosing tag. Did you want a JSX fragment <>...</>? (5:1)
  3 | </svelte:head>
  4 | 
> 5 | <h1>Tic Tac Toe</h1>
    | ^
  6 | 
  7 | <button on:click={newGame}>New Game</button>
  8 | 

Expected behavior: The Svelte file should not be considered JSX, and the code should be accepted and formatted correctly.

Issue Analytics

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

github_iconTop GitHub Comments

0reactions
j-f1commented, Mar 16, 2020

We support JS in <script> tags. I think we might support SCSS in <style> if it’s marked as such.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can't figure out why <span> jumps to next line (svelte material ...
A solution is to use flexbox on the <Formfield> element. Instead of display:inline , try using display:flex -- that alone might fix your...
Read more >
svelte | Yarn - Package Manager
Svelte is a new way to build web applications. It's a compiler that takes your declarative components and converts them into efficient JavaScript...
Read more >
Module context / Sharing code • Svelte Tutorial
Module context / Sharing code • Svelte Tutorial. In all the examples we've seen so far, the <script> block contains code that runs...
Read more >
About Queries | Testing Library
getBy... : Returns the matching node for a query, and throw a descriptive error if no elements match or if more than one...
Read more >
rollup.js
Rollup is a module bundler for JavaScript which compiles small pieces of code ... It uses the new standardized format for code modules...
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