Why is sh (not bash) complaining about functions defined in my .bashrc?

That error happens when bash masquerading as a POSIX shell tries to import those functions from the environment, not when loading them by interpreting a file like ~/.bashrc or such. Simplified example:

foo.bar(){ true; }; export -f foo.bar; bash --posix -c true
bash: error importing function definition for `foo.bar'

I was expecting bash not to load functions from the environment when in posix mode, but it does, and only complains when their names contain funny characters.

Notice that bash will also run in posix mode when the POSIXLY_CORRECT or POSIX_PEDANTIC environment variable is set, or when it was compiled with --enable-strict-posix-default / STRICT_POSIX.

This latter seems to be the case for /bin/sh on MacOS (look here for PRODUCT_NAME = sh), where I expect this error to also trigger when using library functions like popen(3) or system(3).


To answer the part about why read.json and ts-project are not portable function names:

According to POSIX, a function definition must be named by

a word consisting solely of underscores, digits, and alphabetics from the portable character set. The first character of a name is not a digit.

Also known as an identifier, in C lingo. Or in regex: [_a-zA-Z][0-9_a-zA-Z]*