The readme covers the details, but the short summary is that when I set my bsconfig to es6 module format with mjs suffix, an import fails in the generated code of a dependency. It’s possible the dependency is “broken” as it’s quite an old buckle script library. However I have had it working in commonjs format, so I think it should be working in module format as well.
Am I doing something wrong / how can I work around this (without dropping module mode) / did I find a bug in Rescript?
The root cause is that es6 module and commonjs is not 1:1.
There are some features in es6 can not be translated into commonjs, for example, toplevel await, default imports/exports.
For default import in es6, in babel, it was transpiled into
var val = require('module').default
In node, it was emulated as:
var val = require('module')
Neither of them is faithful to es6 import semantics, currently we followed the babel approach
Ah, I thought it would be possible because it’s rescript all the way down, but of course, it’s not. It’s rescript all the way to the js bindings and There lies the problem.
I guess ideally the js community will soon settle on not having common js syntax, but it’s going to be a while before rescript can stop supporting it.