Closed ozyman42 closed 4 years ago
/cc @arcanis
Yep. An alternative is to define @types/json-schema
as optional peer dependency, but it'll require consumers to add it themselves.
/cc @vankop What decision are we making?
I am fine with putting it as dependencies
While it's a little bit weird in my opinion, I don't see a better solution than adding it to dependencies
...
Fixed
Expected Behavior
When using Yarn v2 Berry Plug-n-Play module resolution, typescript to transpile, and requiring webpack 5 as a dependency, the code should compile without issue.
Actual Behavior
typescript gives this error when trying to compile
Yarn v2 Plug-n-Play is strict (which is a good thing) in that it does not allow a package/workspace to require dependencies which are not listed in its package.json dependencies. Even if I add
@types/json-schema
to my own repo's dev dependencies, it still won't fix the issue. The only way I can solve this issue is to modify the yarn lockfile to add"@types/json-schema": ^7.0.4
to thedependencies
ofschema-utils
.Code
How Do We Reproduce?
I've created a demo repository
git clone https://github.com/AlexLeung/schema-utils-typescript-issue-demo
cd schema-utils-typescript-issue-demo
yarn install
yarn start
Notice all these TypeScript errors related to
json-schema
being missingTo fix, you can:
yarn.lock
schema-utils
and add a new line"@types/json-schema": ^7.0.4
yarn install
yarn start
Now you'll notice that all those
json-schema
errors are gone, but I'll need to open a similar issue on the webpack repo itself to solve the issue withestree
.How Do We Solve?
Move
@types/json-schema
from devDependencies to dependencies.As a general rule, whenever you're writing typescript definitions such as the one for schema-utils, if you're going to include another library's types in the definitions which you export, you need to include that library's types as a dependency rather than a devDependency.
Please review the official TypeScript guidelines on Publishing. https://www.typescriptlang.org/docs/handbook/declaration-files/publishing.html See the "Dependencies" section.