package-lock.jsonfiles include more than a single copy of a given set of type definitions—here, types for
@types/ember__object. See below for details on the package manager behavior, and Understanding the Package Names for details on the package names.
npm, you can use
npm upgrade --depth=1 @types/ember__objectto upgrade just that specific dependency and anywhere it is used as a transitive dependency of your top-level dependencies. You can also use its
npm dedupecommand, which may resolve the issue.
yarn, you can specify a specific version of the package to use in the
package.json. For example, if you saw that you had
@types/[email protected]from the default package installs but
some-cool-ts-addon, you could force yarn to use
yarn whyreported you had one version of
@types/ember__objectfrom the normally-installed set of packages, and one from
some-cool-ts-addon, you could run this:
@types/*definitions. That tooling examines the dependencies implied by the package imports and generates a
package.jsonwith those types specified with a
*dependency version. On initial installation of your dependencies, yarn installs the highest version of the package available, and correctly deduplicates that across both your own package and all the
@typespackages which reference each other.
@types/*that you do, and you upgrade your dependence on that type by editing your
package.jsonfile and running
npm installagain, TypeScript will suddenly start offering the error described in detail above:
Duplicate identifier 'EmberObject'.ts(2300)
Ais your app or library, and
Chave the following versions and dependencies:
Cis currently at version
Bis at version
4.5.6. It depends on
*dependency. So the
dependencieskey in its
package.jsonlooks like this:
B(this is the equivalent of installing just the basic type definitions in your package):
Cpublishes a new version,
A(your app or library) adds a dependency on both
yarn), it goes out of its way to leave the existing installation of
Cin place, while adding a new version for you as a top-level consumer. So now you have two versions of
Cinstalled in your
A, your app or library).
deduperesolves to a single version in npm.
"resolutions"field in your
package.jsonsimply forces Yarn to resolve every reference to that package to a single version. This actually works extremely well for types, but it means that every time you either update the types package(s) yourself or update a package which transitively depends on them, you have to edit this value manually as well.