TS Error in compiled dts file due to missing optional dependency `stylelint`
Describe the bug
The stylelint is an optional dependency, but dist/esm/types.d.ts imports it as required.
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.
Reproduction
stylelintis not installed (as it's an optional dependency).tsconfig.jsondoes not haveskipLibCheck: trueset (it's default).- 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.