Skip to content

Check if the main function exists and is exported when bundling#1368

Merged
f-f merged 3 commits into
masterfrom
f-f/detect-main-module
Jan 24, 2026
Merged

Check if the main function exists and is exported when bundling#1368
f-f merged 3 commits into
masterfrom
f-f/detect-main-module

Conversation

@f-f

@f-f f-f commented Jan 22, 2026

Copy link
Copy Markdown
Member

Fix #181 (at last!!) by following my own suggestion from here

@f-f f-f requested a review from fsoikin January 22, 2026 08:17

@fsoikin fsoikin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but here's a suggestion: since we're already parsing the module, how about also checking that the main's type is Effect Unit? It's true that the type could be aliased and not look like Effect Unit, but I think it's a reasonable requirement to have the entry point typed exactly like that. Or, alternatively, it could be a warning. Or can be disabled with a switch.

Comment thread src/Spago/Command/Bundle.purs Outdated
, "Add `main` to the module's export list, remove the explicit export list, or use --bundle-type=module."
]
EntryPoint.ParseError err ->
logWarn $ "Could not verify main export: " <> err

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this also be an error? If the module failed to parse, surely we can't bundle, right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually I just downgraded this to a debug log - the point where we run this is right after a build, so we know that the code compiles; if there's a parse error then the issue must be somewhere else and it's not worth warning the user about it (but still useful to report a debug log in case this is wrong and we need to trace it 🙂)

@f-f

f-f commented Jan 22, 2026

Copy link
Copy Markdown
Member Author

@fsoikin makes sense, I added detection for the Effect Unit type as well!

@f-f f-f merged commit 1628dcf into master Jan 24, 2026
9 of 11 checks passed
@f-f f-f deleted the f-f/detect-main-module branch January 24, 2026 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Spago does not emit an error when bundling an app's main module that does not have a main function

2 participants