How can I import an ES module in the Node.js REPL in Node 8?

It is possible in Node.js v14, but you need to use the import function, rather than the import statement.

$ node

Welcome to Node.js v14.4.0.
Type ".help" for more information.
> let myModule;
undefined
> import("./my-module.js").then(module => { myModule = module });
Promise { <pending> }
> myModule.foo();
"bar"

Leave a Comment