Having a statically linked binary will not always magically solve this, but it's a great step in that direction.
The other step is not relying on any external servers or services, e.g. postgresql, redis, etc.
The rest just boils down to programmer discipline. Never introduce something that can potentially cause a headache to the end user.
If you're building on an interpreted language, you can't really do that. You will always at least require the user to have a specific version of python/node/whatever.
This can get complicated if the user has a different version, so now you have to introduce a virtualization layer that can manage several different versions of the environment. These tools are always annoying to use.
Not to mention that some packages could have native dependencies (e.g. a python library having a dependency on a c library) and this is almost always a source of headaches.