<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi Praveen,<br>
<br>
Sorry for bothering but I just got lots of questions about using
ES modules and I'm not sure who to ask. I tried to read the
history of Debian wiki pages about ES modules and found you.<br>
</p>
<p><br>
</p>
<p>Recently I've updated node-leven package to the latest upstream
version and it becomes an ES module now.<br>
To use ES modules, I wrote a simple "mjs" script file:</p>
<p><span style="font-family:monospace"><span
style="color:#000000;background-color:#ffffff;">import leven
from '/usr/share/nodejs/leven/index.js';
</span><br>
console.log(leven('test', 'test2')); // output: 1<br>
</span></p>
<p><span style="font-family:monospace"><br>
</span></p>
<p><span style="font-family:monospace">The first question is why I
cannot use "import leven from 'leven';"? <br>
</span></p>
<p><span style="font-family:monospace">I got ERR_MODULE_NOT_FOUND if
I don't use the full path.<br>
</span></p>
<p><span style="font-family:monospace">But packages like assert
works without full path.<br>
Not sure if I got things wrong.<br>
</span></p>
<p><span style="font-family:monospace"><br>
</span></p>
<p><span style="font-family:monospace">The second question is more
complicated.<br>
I tried to use leven from a CJS module.<br>
It works if I use dynamic import with full path:</span></p>
<p><span style="font-family:monospace"></span><span
style="font-family:monospace"><span
style="color:#000000;background-color:#ffffff;">var leven;
</span><br>
async function test() {
<br>
leven = await import ('/usr/share/nodejs/leven/index.js');
<br>
leven = leven.default;
<br>
console.log(leven('test', 'test1')); // output 1
<br>
}
<br>
test();<br>
<br>
However, it seems to me that with CJS, there's no top-level
await.<br>
So I can only wrapping things in an async function.<br>
<br>
But this is a bit trouble. How can I simply convert
require('leven') used in node-commist if there's no top-level
await? <br>
I cannot wrap whole node-commist inside an async function
because it should work like a library.<br>
<br>
Yours,<br>
Paul<br>
</span><br>
<span style="font-family:monospace"></span></p>
</body>
</html>