Closed chrisveness closed 5 years ago
for now, you'll have to import with the file extension:
see: https://nodejs.org/api/esm.html#esm_code_import_code_specifiers
Deep import specifiers like 'some-package/lib/shuffle.mjs'. They refer to a path within a package prefixed by the package name.
import mysql from "mysql2/promise.js"
Do you know whether Node.js expects to support this syntax (it looks like it to me), or whether importing CommonJS modules will end up looking different?
the node modules team is still actively working on ironing things out. @jdalton might know more details about this particular topic, since he is a member.
Yes, I can confirm that it works with the file extension:
import mysql from 'mysql2/promise.js';
console.log(mysql);
I can appreciate the arguments against extension-magic, that seems good to me.
Thx
If I have a file
test.js
containing:And I run a command
I see
But if I run a command
I see
Do you know whether Node.js expects to support this syntax (it looks like it to me), or whether importing CommonJS modules will end up looking different?
If it will look like this, is this just a bug which will it be taken care of on the Node.js side, or will they be looking to package developers to make changes?
(I'm using Node.js v12.3.0, ran
npm i mysql2 esm
, and have a package.json containing{ "type": "module" }
).