The js code that compiled by haxe is hard to work together with modern js toolchain.
It can be require
or import
in nodejs env, but can’t in webpack, rollup and esbuild. The code register itself to window in browser envirment and exports nothing!! It’s reminds me of 10 years ago.
There’s the method:
Add a line to start of generated code var exports = {};
.
// Generated by Haxe 4.3.4
var exports = {};
(function ($hx_exports, $global) { "use strict";
Edit the last line:
})(typeof exports != "undefined" ? exports : typeof window != "undefined" ? window : typeof self != "undefined" ? self : this, typeof window != "undefined" ? window : typeof global != "undefined" ? global : typeof self != "undefined" ? self : this);
to
})(exports);
export default exports;
finally, rename file to .mjs
;
Now it’s an esm. Maybe use macro can make it be auto-generated, but i’m a beginner of haxe, still not know how to do this.