improve commonjs packaging detection

root.require is not always available (eg. in browserify and node) so the
detection fails.  require should always be a function in scope within a
module, though.