developit / developit/microbundle
package.json types/main/module take precedence over conditional exports
- Linguagem predominante
- JavaScript
- Estrelas
- 8.1k
- Forks
- 358
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Possibly somewhat related to #1085.
Given a package.json:
```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:
```sh
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 `tsc` causes no issues.
Guia de contribuição
Nenhum guia de contribuição indexado para este repositório
Direção de pesquisa
Reproduza o problema com o exemplo de package.json usando `microbundle --target node -f esm --generateTypes=true` e, em seguida, compare o resultado com `tsc`. Inspecione como o build lida com os campos `exports`, `main`, `module` e `types` do package.json juntamente com as configurações `resolvePackageJsonExports` e `moduleResolution` do tsconfig.json. A tarefa estará concluída quando as exportações condicionais resolverem os tipos declarados sem exigir um campo `types` na raiz.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- javascript, nodejs, rollup, typescript
- Domínio
- build-system, tooling
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 35/100