Doing \begin{document} under the scope of \ExplSyntaxOn is a very bad idea, sorry.
Several packages delay loading configuration files at begin document and inputting a file under the \ExplSyntaxOn regime is, to say the least, risky: spaces and endlines are ignored and if a file does
\mycountera=100
\ifnum\mycounterb=\mycountera 10\else 0\fi
(made up code to show one of the possible issues) you'd end with \mycountera holding the value 10010 or 1000, depending on the current value of \mycounterb. The given code is valid and would set \mycountera to 100 when spaces aren't ignored, then print 10 or 0. But when spaces are ignored, the \ifnum is expanded prior to TeX having determined the value passed to \mycountera.
Think to \ExplSyntaxOn as bringing an aircraft to the hangar for installation of new equipment. You want to end the installation before pulling the aircraft on the runway for take-off, don't you?
When you're under \ExplSyntaxOn regime, never do typesetting. Well, sometimes
\ExplSyntaxOn<expl3 code>\ExplSyntaxOff
might be appealing inside document. Avoid it and define prior to \begin{document} a user level command doing the business: install the equipment first, then take-off.
David's answer to Checking whether an item of a string is space is a case: his usage of \ExplSyntaxOn inside document was just by way of example, but not aimed to be what you'd do in a real document.
\ExplSyntaxOnafter\begin{document}can fix. – user202729 Dec 25 '22 at 06:40\ExplSyntaxOnjust before\begin{document}and several for not doing it. – egreg Dec 25 '22 at 08:58