Jianwu Chen
1 min readApr 26, 2021

--

Thanks for the great package. It's very useful. Also glad to know you are also the creator of my favorite package Lodash.

Recently I tried to integrate esm with my package https://www.npmjs.com/package/remote-import

I got a weird problem. My package overrides module._resolveFilename to load modules from a URL. To support ES modules. I integrated it with esm. When run it in node script mode. It works fine to preload both modules

e.g.

node -r esm -r remote-import sample/sample.js # works

But in REPL mode, it doesn't work

node -r esm -r remote-import

> import 'sample/sample.js' // doesn't work

The overridden module._resolveFilename doesn't take affect.

In REPL mode, if I just preload esm, and manually import remote-import. it works, e.g.:

node -r esm

> import 'remote-import'

> import 'sampe/sample.js'

Tried to figure out what's the different between REPL and script mode by reading esm source code. It's a bit too difficult for me to get any clue.

Not sure if you have any idea on this problem and if there's any work around of that. I want to support REPL mode without any manual imports.

--

--

Jianwu Chen

Passionate Open Source Developer. ex-Ebayer, ex-Googler, ex-Linkin-er