Hi people :). For more than 5 years I’ve been toiling away at a rather massive Haxe project, which I intended and still intend to be a pretty major release for the ecosystem. It’s still under wraps however, until I clarify some patent concerns. Anyway, suffice to say I poured a lot into it.
I’m relying on externs to accomplish some of the things I’m doing, because I’m transpiling to NodeJS. Until now, I’ve been using @haxiomic 's excellent dts2hx library for adding new libraries when I needed them. But now I’m having some weird issue with it not generating externs for a very simple library I created.
This is the library. The only thing I’m interested in exporting from it is the SReader.readCharacters function:
It’s meant to also contain a service, but that’s not relevant for the export. For now, I just want to export a single function from the thing, and I have trouble on both tracks:
First, dts2hx doesn’t seem to work properly for it. I install it locally using npm pack
and npm install shardyard
in another project, but then when I run npx dts2hx shardyard
, dts2hx complains that it can’t find the module. For whatever weird reason, it tries to find shardyard
in the root of node_modules
. Have absolutely zero clue why it does that.
So then I tried to create externs manually. I made this class:
@:jsRequire("shardyard/dist/SReader") @valueModuleOnly extern class SReader
{
static function readCharacters (): Array<NCharacter>;
}
@:jsRequire("shardyard/dist/vo/NCharacter") @valueModuleOnly extern class NCharacter
{
public var name: String;
}
And I use it like so:
logger.debug(SReader.readCharacters());
Which compiles fine. But when it runs, I get:
node:internal/modules/cjs/loader:1544
throw err;
^
Error [ERR_REQUIRE_ESM]: require() of ES Module my_project_path\node_modules\shardyard\dist\SReader.js from my_project_path\export\main.js not supported.
Instead change the require of SReader.js in my_project_path\export\main.js to a dynamic import() which is available in all CommonJS modules.
What’s that whole thing with dynamic import() ?
And can anybody help me use dts2hx? I would very much prefer that it works, because it makes it much easier to generate externs and keep them updated.