Skip to content

Commit ee02b7b

Browse files
committed
Solve minor bug from node port require.
1 parent 38df194 commit ee02b7b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

source/ports/node_port/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ mod.prototype.require = function (name) {
162162

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

185185
/* If there is no extension or the extension is not supported or it is 'node', load it with NodeJS require */
186186
try {
187-
/* Cache the port */
188-
if (require.resolve(name) === path.resolve(__filename)) {
187+
const filename = require.resolve(name);
188+
189+
/* Cache the port (detect if this file is being loaded) */
190+
if (filename === path.resolve(__filename)) {
189191
return module_exports;
190192
}
193+
191194
/* Call to real NodeJS require */
192-
return node_require.apply(this, [ name ]);
195+
return node_require.apply(this, [ filename ]);
193196
} catch (e) {
194197
/* If it is not a NodeJS module, try to guess the runtime */
195198
const loaders = new Set(Object.values(tags));

0 commit comments

Comments
 (0)