diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/repl.js | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/repl.js b/lib/repl.js index e304bc2e77..c1473588d3 100644 --- a/lib/repl.js +++ b/lib/repl.js @@ -332,10 +332,12 @@ function REPLServer(prompt, if (code === '\n') return cb(null); - let pwd; + let parentURL; try { const { pathToFileURL } = require('url'); - pwd = pathToFileURL(process.cwd()).href; + // Adding `/repl` prevents dynamic imports from loading relative + // to the parent of `process.cwd()`. + parentURL = pathToFileURL(path.join(process.cwd(), 'repl')).href; } catch { } while (true) { @@ -350,7 +352,7 @@ function REPLServer(prompt, filename: file, displayErrors: true, importModuleDynamically: async (specifier) => { - return asyncESM.ESMLoader.import(specifier, pwd); + return asyncESM.ESMLoader.import(specifier, parentURL); } }); } catch (e) { |