Skip to content
These are temporary community docs. The official docs are in progress.Help improve them
Markless
Esc
↑↓navigate↵open⌘Jpreview
On this page

MARKLESS_STATE_MODULE_SCOPE

state() or computed() sits at the top of a file instead of inside a component.

Error from the compiler, while it builds your .tsrx files.

What happened

A value at the top of a file belongs to every request on the server, not to one page. So Markless refuses state() and computed() there.

Markless prints the message, the reason, and a suggestion:

MARKLESS_STATE_MODULE_SCOPE: Cannot create "<name>" with <callName>() at module scope.
Module-scope graph state would be shared across requests and has no per-document serialization payload.
Move state() or computed() creation into a component or declare request/container/page state with shared().
https://markless.dev/errors/MARKLESS_STATE_MODULE_SCOPE

Words in angle brackets change from case to case.

How to fix it

Move the call into the component body. If many components need the same value, use shared() instead.

export function Counter() @{
	let count = state(0);

	<button onClick={() => count++}>{count}</button>
}

Where it comes from

@markless/compiler raises this code. Source:

Read how to read a Markless error, or go back to all error codes.

Was this page helpful?