arethetypeswrong / arethetypeswrong.github.io

Tool for analyzing TypeScript types of npm packages

Home Page:https://arethetypeswrong.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Incorrectly passes `bundler` even if `exports.*.types` is missing

fregante opened this issue · comments

See https://arethetypeswrong.github.io/?p=css-selector-generator%403.6.4

See https://github.com/fczbkk/css-selector-generator/blob/68902ba94b61ed819eb4847c8cceab1d483d1f1d/package.json#L10-L13

From what I see, moduleResolution:bundler and node16 actually fails if the types are not specified in the exports map, but this tool passes them both.

Screenshot

I submitted a PR to fix it https://togithub.com/fczbkk/css-selector-generator/pull/577/files

These resolutions are working correctly (both in tsc and in this tool) via file extension substitution. The import condition specifies ./esm/index.js, so TypeScript will successfully find ./esm/index.d.ts.

Uhm, that's not what I'm seeing.

CI results: can't find the types

https://github.com/pixiebrix/pixiebrix-extension/actions/runs/6650563402/job/18070905027#step:5:1

The error message is very clear:

There are types at '/home/runner/work/pixiebrix-extension/pixiebrix-extension/node_modules/css-selector-generator/types/index.d.ts', but this result could not be resolved when respecting package.json "exports". The 'css-selector-generator' library may need to update its package.json or typings.

This is the tsconfig: it worked when the resolution was just node but not on bundler

https://github.com/pixiebrix/pixiebrix-extension/blob/a2b04ba31401e122a141138478021fa400b7b817/tsconfig.json#L8

The module can only be correctly imported by TypeScript after making the exports suggested in the linked PR.

@andrewbranch if you're interested in resolving this I can work on a repro

All the files where the error appears are CJS files, so the errors you’re seeing correspond to the node16 (from CJS): ❌ No types row.

Oh wait, but your moduleResolution is set to bundler there? Something weird is going on. But it’s definitely something in your project, not this tool—the results from the tool match what I see looking at the source code. The results in CI are surprising. Try adding --traceResolution to the tsc invocation?