macOS ships the BSD userland, where 'sed -i' takes a mandatory extension argument for the backup file. 'sed -i s/a/b/ file' consumes 's/a/b/' as the suffix and then reports 'sed: 1: "file": invalid command code f', which is one of the most confusing error messages in day-to-day shell work. The GNU form, where -i alone edits in place, is what almost every tutorial shows.
The portable in-place edit is 'sed -i "" -e s/a/b/ file' on macOS and 'sed -i -e s/a/b/ file' on GNU, and no single invocation works on both. Scripts that must run in both places should write to a temporary file and move it, or detect the platform once.
The same divergence affects other tools. date has -v for relative arithmetic on BSD and -d on GNU; stat uses -f with a format string on BSD and -c on GNU; xargs has no -r on BSD, though it also does not run the command on empty input; and readlink and mktemp differ. Installing coreutils and gnu-sed from Homebrew provides the GNU versions under a g prefix, or unprefixed by adding the gnubin directory to PATH.