Since a Typst update (about a year ago, I’d say), I can no longer use my file to format my other files.
The issue seems to stem from the header: locate...
Nowadays we would write context { counter(page).get() /* do the rest of your work in here; just as with locate, you can no longer do logic on it or read properties outside of this bracket → */ } to retrieve the current page counter value, or here() within a context block to get the current location as a value like loc in your snippet: Context - Typst Documentation.
We could also write it a bit more compact; here the statement after context is the if expression itself not a code-block containing one. It is equivalent to the above syntactically:
header: context if counter(page).get().first() < 2 {
set text(12pt)
chapitre
h(1fr)
classe
}