Hi Praveen,

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.


Recently I've updated node-leven package to the latest upstream version and it becomes an ES module now.
To use ES modules, I wrote a simple "mjs" script file:

import leven from '/usr/share/nodejs/leven/index.js';
console.log(leven('test', 'test2')); // output: 1


The first question is why I cannot use "import leven from 'leven';"?

I got ERR_MODULE_NOT_FOUND if I don't use the full path.

But packages like assert works without full path.
Not sure if I got things wrong.


The second question is more complicated.
I tried to use leven from a CJS module.
It works if I use dynamic import with full path:

var leven;
async function test() {
   leven = await import ('/usr/share/nodejs/leven/index.js');
   leven = leven.default;
   console.log(leven('test', 'test1')); // output 1
}
test();

However, it seems to me that with CJS, there's no top-level await.
So I can only wrapping things in an async function.

But this is a bit trouble. How can I simply convert require('leven') used in node-commist if there's no top-level await? I cannot wrap whole node-commist inside an async function because it should work like a library.

Yours,
Paul

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

-- 
Pkg-javascript-devel mailing list
Pkg-javascript-devel@alioth-lists.debian.net
https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/pkg-javascript-devel

Reply via email to