For reference, ESbuild can produce an esm bundle with a set of next options: bundle: true, format: 'esm', and platform: 'node'. Although I was able to do that with JS-based codebase.
bundle: true
format: 'esm'
platform: 'node'