vite-plugin-checker icon indicating copy to clipboard operation
vite-plugin-checker copied to clipboard

TS Error in compiled dts file due to missing optional dependency `stylelint`

Open qwqcode opened this issue 2 years ago • 0 comments

Describe the bug

The stylelint is an optional dependency, but dist/esm/types.d.ts imports it as required.

package.json#L78-L80

src/types.ts#L74

Consequently, if stylelint isn't installed, consumers without skipLibCheck (tsconfig.json) enabled will encounter a TypeScript error reported in the declaration files within their node_modules directory from the package.


node_modules/vite-plugin-checker/dist/esm/types.d.ts:4:28 - error TS2307: Cannot find module 'stylelint' or its corresponding type declarations.

image

Reproduction

  1. stylelint is not installed (as it's an optional dependency).
  2. tsconfig.json does not have skipLibCheck: true set (it's default).
  3. perform type checking

Expected behavior

expect no TypeScript type errors

System Info

Binaries:
    Node: 18.19.0 - ~/.volta/tools/image/node/18.19.0/bin/node
    Yarn: 4.0.2 - ~/.volta/tools/image/yarn/4.0.2/bin/yarn
    npm: 10.2.3 - ~/.volta/tools/image/node/18.19.0/bin/npm
    pnpm: 7.33.6 - ~/.volta/bin/pnpm
  Browsers:
    Chrome: 120.0.6099.109
    Safari: 17.1.2

Additional context

Consider making stylelint a required dependency or finding an alternative method to import the stylelint type.

One solution is to add // @ts-ignore to the previous line of import * as Stylelint from 'stylelint', but after I tried it, the packaging tool always removes the comment. 😢

Reference: https://stackoverflow.com/questions/54392809/how-do-i-handle-optional-peer-dependencies-when-publishing-a-typescript-package/

Validations

  • [X] Read the docs.
  • [X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.

qwqcode avatar Dec 27 '23 08:12 qwqcode