#1985·oclif

Allow explicit esm/cjs flag with "explicit" loader

Author: sergei-dyshelCreated Feb 26, 2026Updated Sep 18, 2026
LabelsUSER STORYstale

I'm using Oclif to build self-contained CLIs. The final executables are using shebang and have no extension, like regular executables on Linux. For that I'm using explicit strategy and bundler (esbuild in my case).

One issue I'm facing with migration to ESM is that Oclif decides whether to use import target (basically executable file imports itself) based on extension, and for files recognizable extension it uses CJS by default.

Here's the relevant code https://github.com/oclif/core/blob/5072476765a1c740fa3f38869efbc1db86f12fd6/src/module-loader.ts#L133-L153

I think we need to give user more control and let him decide how to import the commands. Adding another (boolean) field to CommandDiscovery for that would be nice.