Concrete
Rulesworkspace

concrete/workspace/module-invalid

A workspace module fails to build or throws when it is evaluated.

A workspace module fails to build or throws when it is evaluated.

Graded by the workspace stage of concrete check, in the tree venue. A violation reports this id and the file it failed at — see every rule and concrete check.

Reason

A workspace is loaded whole: every module under the root is built and evaluated before anything is graded, because a section is discovered by being exported and a page is a value the site map holds. Module scope therefore runs on every check, every dev start and every build — so work that can fail there takes the whole load down, and no other rule gets an input to grade.

Fix

Keep module scope to declarations. Move anything that reads a file, parses input or can throw into the render, which runs per fixture, or into compute(), which runs at derive time with the facts it needs.

Before and after

import { Section, section, Slot, text } from "@homepages/concrete";

// Runs the moment the workspace loads this module, and throws.
const brand = readBrand();

function readBrand(): string {
  throw new Error("brand.json is not part of the workspace");
}

export const Hero = section(
  { key: "hero", label: "Hero", slots: { headline: text.medium({ label: "Headline" }) } },
  ({ slot }) => (
    <Section>
      <p>{brand}</p>
      <Slot.Text slot={slot.headline} as="h1" />
    </Section>
  ),
);
import { Section, section, Slot, text } from "@homepages/concrete";

const brand = "Meridian";

export const Hero = section(
  { key: "hero", label: "Hero", slots: { headline: text.medium({ label: "Headline" }) } },
  ({ slot }) => (
    <Section>
      <p>{brand}</p>
      <Slot.Text slot={slot.headline} as="h1" />
    </Section>
  ),
);

On this page