make-runnable package works only on CommonJS, and base on this rules of import-export in CommonJS and ESModule :
https://miro.medium.com/max/875/1*3cI3YvzG0HakM7VCaxtbfA.png
I can not figure how to solve this my apps.
...
I am currently work on ESModule, so I need all of my code in modules type.
Here is my code on the file who need to import .mjs file:
const students = require('../../repository/students.mjs')
function drop() {
students.drop()
}
module.exports = {
drop
}
require('make-runnable/custom')({
printOutputFrame:false
})
And when I run node path/to/my/file/index.js drop, this is the error ouput:
node:internal/modules/cjs/loader:979
throw new ERR_REQUIRE_ESM(filename, true);
^
Error [ERR_REQUIRE_ESM]: require() of ES Module my/path/to/api/controller.mjs not supported.
Instead change the require of my/path/to/api/controller.mjs to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (my/path/to/index.js:1:18) {
code: 'ERR_REQUIRE_ESM'
}
Is there any chance to make make-runnable packages can be run on ESModule?
Or is there another way to run a function from CLI with ESModule?