Give a clear error when a board has no export - #3835
Draft
posthog[bot] wants to merge 1 commit into
Draft
Conversation
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
|
This PR has been automatically marked as stale because it has had no recent activity. It will be closed if no further activity occurs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
<board>...</board>with no export, and gets React's rawElement type is invalid ... but got: object— a pointer at React internals, not the one-line fix they need.__esModulemarker, somodule.exportsstays{}.lib/eval/eval-compiled-js.tsthen hands that empty object back asdefault. It is truthy, so the entrypoint's(() => null)fallback never fires and the empty object reachescircuit.add.runTscircuitCode.tsguard that catches a missingexportkeyword only runs for string input, so the editor's fsMap path skips it.Changes
eval-compiled-js.ts, returnundefinedfordefaultwhen the module object has no own keys, so an empty module no longer reads as a component.(() => 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 addexport default.index.tsxin the fsMap pins the new error.Result
Before:
After:
Created with PostHog Desktop from this inbox report.