package.json types/main/module take precedence over conditional exports
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript, nodejs, rollup, typescript
- Domain
- build-system, tooling
Research direction
Reproduce the issue with the package.json example using microbundle --target node -f esm --generateTypes=true, then compare the result with tsc. Inspect how the build handles the package.json exports, main, module, and types fields alongside the tsconfig.json resolvePackageJsonExports and moduleResolution settings. Done means conditional exports resolve the declared types without requiring a root types field.
Written by the indexing model from the issue text.
Description
Possibly somewhat related to #1085.
Given a package.json:
{
"main": "./lib/index.cjs",
"module": "./lib/index.js",
"type": "module",
"dependencies": {
"some-client-with-matching-esm-and-tsconfig": "^x.x.x"
},
"exports": {
".": {
"require": {
"types": "./lib/index.d.ts",
"default": "./lib/index.cjs"
},
"import": {
"types": "./lib/index.d.ts",
"default": "./lib/index.js"
}
},
"./package.json": "./package.json"
},
_without root types property, running:
microbundle --target node -f esm --generateTypes=true
results in error:
(rpt2 plugin) Error: /Users/xxxx/dev/project/dependingclient.ts(197,32): semantic error TS2339: Property 'request' does not exist on type 'DependingClient.ts'.
at RollupContext.error (/Users/xxxx/dev/project/node_modules/rollup-plugin-typescript2/dist/rollup-plugin-typescript2.cjs.js:20259:3
Indicating it cannot find the types specified in the conditional exports.
Working solution: Specify "types": "./lib/index.d.ts" at root-level.
Also works: Remove the "main" and module property
It seems to me package.json conditional exports are not taking precedence over main/module/types
Not sure if related but when in tsconfig.json resolvePackageJsonExports is explicitly set to true (even weirder is that it would be true by default in node16 moduleresolution) , regardless of whether moduleResolution is set to node16, it throws
rpt2: options error TS5098: Option 'resolvePackageJsonExports' can only be used when 'moduleResolution' is set to 'node16', 'nodenext', or 'bundler'. Whereas running the build simple with
tsccauses no issues.
- Dominant language
- JavaScript
- Stars
- 8.1k
- Forks
- 358
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from developit/microbundle
-
CSS
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
developit/microbundle#1002 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
developit/microbundle#789 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
developit/microbundle#1100 · 4 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 45/100
developit/microbundle#1093 · 3 comments · 1 reaction ·
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
developit/microbundle#1092 ·
All issues in developit/microbundle
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·