Backport of 1102006 from trunk. Fix handling of circular imports in CommonJS modules. Thanks to Caolan McMahon for the patch. Closes COUCHDB-1075