I've got a lot of hallucinations like that from LLMs. I really don't get how so many people can get LLMs to code most of their tasks without those issues permanently popping up.
I've used it for some smaller greenfield code with success. Like, write an Arduino program that performs a number of super-sampled analog readings, and performs a linear regression fit, printing the result to the serial port. That sort of stuff can be very helpful to newbies in the DIY electronics world for example. But for anything involving my $dayjob it's been fairly useless beyond writing unit test outlines.
You also have to be very explanatory with a direct communication style.
Our system imports the codebase so it can search and navigate plus we feed lsp errors directly to the LLM as development is happening.