diff --git a/source/ports/node_port/index.js b/source/ports/node_port/index.js index f0a0a5062..26628711a 100644 --- a/source/ports/node_port/index.js +++ b/source/ports/node_port/index.js @@ -214,34 +214,25 @@ mod.prototype.require = function (name) { // /* Continue loading */ // } - /* Try to load it with NodeJS first */ - try { - return node_require.apply(this, [ name ]); - } catch (e) { - if (e.code !== 'MODULE_NOT_FOUND') { - throw e; - } - } - - try { - return node_require.apply(this, [ require.resolve(name) ]); - } catch (e) { - if (e.code !== 'MODULE_NOT_FOUND') { - throw e; - } - } - const index = name.lastIndexOf('.'); if (index !== -1) { - /* If there is extension, load the module depending on the tag */ - const extension = name.substr(index + 1); - const tag = tags[extension]; + /* If there is extension, load the module depending on the tag */ + const extension = name.substr(index + 1); + const tag = tags[extension]; - if (tag && tag !== 'node') { - /* Load with MetaCall if we found a tag and it is not NodeJS */ - return metacall_require(tag, name); - } + if (tag && tag !== 'node') { + /* Load with MetaCall if we found a tag and it is not NodeJS */ + return metacall_require(tag, name); + } + } + + try { + return node_require.apply(this, [ name ]); + } catch (e) { + if (e.code !== 'MODULE_NOT_FOUND') { + throw e; + } } /* If there is no extension or the extension is not supported or it is 'node', load it with NodeJS require */