Skip to content

A project depending on unocss with a CJS build no longer builds since v66.5.11 #5071

@grant-progress

Description

@grant-progress

UnoCSS version

66.5.11

Describe the bug

Feel free to close this as invalid if you explicitly don't want to support depending on unocss or other core modules in a project built using "module": "commonjs" and/or "moduleResolution": "node".

Since #5016, UnoCSS core packages have specified their types import as explicitly using ESM syntax via .mts. I have a library which defines an UnoCSS plugin that I want to be available in both module formats (not open-source; see repro example below for minimal repro) which depends on unocss and other core packages internally and has a dual-build setup which also emits a CJS build via { "module": "commonjs" }, which requires moduleResolution of node (or node10). When attempting to build this library in CJS mode, Typescript complains to the tune of:

'unocss/dist/index.mjs' implicitly has an 'any' type.
  There are types at '/home/projects/unocss-unocss-c2aigchr/node_modules/unocss/dist/index.d.mts', but this result could not be resolved under your current 'moduleResolution' setting. Consider updating to 'node16', 'nodenext', or 'bundler'.

1 import * as uno from 'unocss';

Meaning, while in CommonJS resolution mode, it refuses to read typings from .d.mts. This used to work before the extension change, even if perhaps it worked for a bad reason. I assume from the .mjs imported filename that TS is already trying to do ESM interop, and the .m.ts extension of the prior typings files was sufficiently ambiguous for it to manage to infer typings.

Reproduction

https://stackblitz.com/edit/unocss-unocss-c2aigchr?file=src%2Fmain.ts

Run npm run tsc to see the Typescript compilation error. Note the use of module: "commonjs" in tsconfig.json.

System Info

MacOS 26.2, Node 22, Typescript 5.9.3

Validations

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions