privatenumber / pkgroll

📦 Zero-config package bundler for Node.js + TypeScript
MIT License
1.21k stars 29 forks source link

cannot generate tsx types #99

Closed uinz closed 2 weeks ago

uinz commented 3 weeks ago

Problem

dts does not correctly generate types for tsx files when using a specific tsconfig.

# File Struct
.
├── src
├── tsconfig.example.json
├── tsconfig.json
├── tsconfig.src.json
└── vite.config.ts
// tsconfig.json
{
  "files": [],
  "references": [
    { "path": "./tsconfig.example.json" },
    { "path": "./tsconfig.src.json" }
  ]
}
// tsconfig.src.json
{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "lib": ["ES2020", "DOM", "DOM.Iterable"],
    "module": "ESNext",
    "skipLibCheck": true,

    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "noUncheckedIndexedAccess": true,
    "isolatedModules": true,
    "noImplicitOverride": true,
    "moduleDetection": "force",
    "noEmit": true,
    "jsx": "react-jsx",
    ^^^^^^^^^^^^^^^^^^^
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true
  },
  "include": ["src"]
}

run command

pkgroll -p tsconfig.src.json

# got an error
src/index.ts(2,15): error TS6142: Module './components/stats' was resolved to 
'/xxx/src/components/stats/index.tsx', but '--jsx' is not set.
                                       ^^^^^^^^^^^^^^^^^^^^^^^

https://github.com/privatenumber/pkgroll/blob/2a988e454bd8fd163b567e5fa2e67ab89864c3f3/src/utils/get-rollup-configs.ts#L61

Expected behavior

I found that it was because the specified tsconfig path was not passed to rollup-plugin-dts, so rollup-plugin-dts used the root path's tsconfig.json by default

Just pass the specified tsconfig path to rollup-plugin-dts to fix this problem.

Minimal reproduction URL

https://stackblitz.com/edit/stackblitz-starters-ayudec

Version

v2.5.0

Node.js version

v22.6.0

Package manager

pnpm

Operating system

macOS

Bugs are expected to be fixed by those affected by it

Compensating engineering work financially will speed up resolution

privatenumber commented 2 weeks ago

:tada: This issue has been resolved in version 2.5.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket: