Skip to content

Give a clear error when a board has no export - #3835

Draft
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixeval-give-a-clear-error-when-the-b9f25c
Draft

Give a clear error when a board has no export#3835
posthog[bot] wants to merge 1 commit into
mainfrom
posthog-self-driving/fixeval-give-a-clear-error-when-the-b9f25c

Conversation

@posthog

@posthog posthog Bot commented Aug 11, 2026

Copy link
Copy Markdown

Problem

  • A first-time user in the tscircuit.com editor writes a bare <board>...</board> with no export, and gets React's raw Element type is invalid ... but got: object — a pointer at React internals, not the one-line fix they need.
  • A file with no imports or exports makes Sucrase emit no __esModule marker, so module.exports stays {}.
  • The require interop in lib/eval/eval-compiled-js.ts then hands that empty object back as default. It is truthy, so the entrypoint's (() => null) fallback never fires and the empty object reaches circuit.add.
  • The runTscircuitCode.ts guard that catches a missing export keyword only runs for string input, so the editor's fsMap path skips it.
  • Small in volume, but it is the exact first-circuit mistake, and the sibling JSX-literal case already gets a friendly message — so this is a gap in diagnostics that already exist.

Changes

  • Interop: in eval-compiled-js.ts, return undefined for default when the module object has no own keys, so an empty module no longer reads as a component.
  • Entrypoint: the generated entrypoint drops the silent (() => null) fallback and instead checks the resolved component is a function. If not, it throws a tscircuit-worded error that names the file and tells the user to add export default.
  • Test: a single no-export index.tsx in the fsMap pins the new error.

Result

Before:

Error evaluating "entrypoint.tsx": Element type is invalid ... but got: object.

After:

Error evaluating "entrypoint.tsx": No component was exported from "index.tsx".
You need to export a component, e.g.

export default () => (
  <board width="10mm" height="10mm" />
)

Created with PostHog Desktop from this inbox report.

A file with no imports or exports produces an empty exports object with no
__esModule marker. The require interop passed that empty object off as a
default export, so a bare-JSX board with no export read as a truthy component
and reached React, which threw its generic "Element type is invalid ... but
got: object" message.

The interop now returns undefined for the default export when the module has
no own keys, so the generated entrypoint's fallback fires. The entrypoint then
checks that the resolved component is a function and throws a tscircuit-worded
error that names the file and tells the user to add an export.

Generated-By: PostHog Desktop
Task-Id: b21cf508-b5b8-4648-9430-21c7cfc2e8c3
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants