Skip to content

Prettier in Svelte 5 does not recognize <script module>, preferring the deprecated <script context='module'> #484

@hmprt

Description

@hmprt

Svelte allows for components with two script tags, so long as one is a <script module>.

<script lang='ts' module>
...
<script lang='ts'>

If you do this however, prettier complains and will stop formatting documents, saying:
ParseError: A component can only have one instance-level <script> element

The solution is to use deprecated syntax to achieve the same result:

<script lang='ts' context='module'>
<script lang='ts'> 

However this produces a svelte linter warning at the top of the documents:
context="module" is deprecated, use the 'module' attribute instead
After making this change, prettier formatting starts working again.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions