Subject: Motoko Syntax Errors: “unexpected token ‘private’” and Type Definition Issues
Hi everyone,
I’m running into persistent Motoko syntax errors in my project, and after following all the usual advice, I still can’t resolve them. Here’s what’s happening:
Main Error:
unexpected token 'private', expected one of token or <phrase> sequence:
<eof>
seplist(<dec>,<semicolon>) (e.g. 'let x : Int = 0')
Context:
- The error appears right after my type definitions at the top of my
actorinmain.mo. - I have several custom types, both variants and records, e.g.:
type SearchRequest = { query: Text; scope: SearchScope; filters: ?SearchFilter; sortBy: ?SearchSortBy; pagination: ?PaginationParams } // <--- I tried with and without a semicolon here - I’ve tried:
- Adding/removing semicolons after every field and after the closing brace of record types.
- Ensuring no semicolon after the last tag in variant types, but a semicolon after the closing brace.
- Reordering and reformatting the type definitions.
- No matter what I do, the parser always throws an error at the first
privatedeclaration after the types.
What am I missing?
- Is there a subtle Motoko syntax rule I’m overlooking for type definitions inside an actor?
- Could this be a tooling or compiler bug?
- Any working example of a Motoko actor with multiple custom types (both variant and record) at the top would be super helpful!
Thanks in advance for any help or pointers!