Skip to content

Commit

Permalink
Solve minor bug from node port require.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Jan 20, 2021
1 parent 38df194 commit ee02b7b
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions source/ports/node_port/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ mod.prototype.require = function (name) {

/* Try to load it with NodeJS first */
try {
return node_require.apply(this, [ name ]);
return node_require.apply(this, [ require.resolve(name) ]);
} catch (e) {
if (e.code !== 'MODULE_NOT_FOUND') {
throw e;
Expand All @@ -184,12 +184,15 @@ mod.prototype.require = function (name) {

/* If there is no extension or the extension is not supported or it is 'node', load it with NodeJS require */
try {
/* Cache the port */
if (require.resolve(name) === path.resolve(__filename)) {
const filename = require.resolve(name);

/* Cache the port (detect if this file is being loaded) */
if (filename === path.resolve(__filename)) {
return module_exports;
}

/* Call to real NodeJS require */
return node_require.apply(this, [ name ]);
return node_require.apply(this, [ filename ]);
} catch (e) {
/* If it is not a NodeJS module, try to guess the runtime */
const loaders = new Set(Object.values(tags));
Expand Down

0 comments on commit ee02b7b

Please sign in to comment.