Got stuck importing a sibling package from the ESM side of a monorepo.
@repo/ui has no "type" field in its package.json, and its exports looks like this. "types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs". The consumer is "type": "module" with moduleResolution set to nodenext.
Okay, I write import ui from '@repo/ui' and type ui(. The editor says the value isn't callable. I type ui. and completion offers default. (That part made me laugh.) Switch to ui.default() and the type check passes, but at run time Node takes the import condition and loads the real ESM file, which has no such property.
Rereading the handbook's modules reference, a .d.ts counts as CommonJS when the nearest package.json has no "type": "module". So the types describe a CJS module while the runtime loads an ESM one. A default import of CJS from ESM gets the whole module.exports, hence the extra layer of default.
What's the cleanest fix here? I'm torn between a declaration file per condition and just turning the package into ESM.