to reproduce:
make a datapack with a function, any name will do.
in this function, paste this line:
say nearest to me: @e[sort=nearest,type=!player,limit=1]
put down any command block and paste this line:
execute as @p run function namespace:function
now, put any entity close to this command block except players
go away so you can have a different entity close to you
activate the command block by any means
it should say:
[your name here] nearest to me: <entity near command block>
correct output SHOULD be:
[your name here] nearest to me: <something actually near you>
the screenshot attached demonstrates this.
It's intentional, you need to use /execute as @p at @s run function <namespace>:<function>