Reinstate check for typeof `require` == "function"

This is still an imperfect test for the presence of CommonJS, but
at least it will not attempt to call `require` if it doesn't exist.