I noticed that generateDirectusTypes is using the DIRECTUS_PUBLIC_TOKEN to get the type definition file.
As per documentation of the directus-sdk-typegen, the token must be a token with administrator permissions, the token for the public role is not suited for that.
I've seen it in astra, svelte and the nextjs cms starter frontend.