diff options
author | Corey Farrell <git@cfware.com> | 2019-11-22 22:06:43 -0500 |
---|---|---|
committer | bcoe <bencoe@google.com> | 2019-11-30 20:07:52 -0800 |
commit | 49fb529139ff4b43f472e24f2015482af82446b6 (patch) | |
tree | e6eca7fb0ec36c92d6afbb45a3cbe1fd5affd09f /lib | |
parent | 6bf5a1d691291cdfcc4941e68f00d0003e565476 (diff) | |
download | android-node-v8-49fb529139ff4b43f472e24f2015482af82446b6.tar.gz android-node-v8-49fb529139ff4b43f472e24f2015482af82446b6.tar.bz2 android-node-v8-49fb529139ff4b43f472e24f2015482af82446b6.zip |
repl: fix referrer for dynamic import
The ESM loader does not accept a directory as the referrer, it requires
a path within the directory. Add `/repl` to ensure relative dynamic
imports can succeed.
Fixes: https://github.com/nodejs/node/issues/19570
PR-URL: https://github.com/nodejs/node/pull/30609
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ben Coe <bencoe@gmail.com>
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) { |