重复标识符“LibraryManagedAttributes" [英] Duplicate identifier 'LibraryManagedAttributes'
问题描述
我有同样的问题:
React typescript (2312,14):重复标识符LibraryManagedAttributes"一个>
和
TypeScript 错误:重复标识符LibraryManagedAttributes"
但我就是找不到任何解决方案.
But I just can't find any solution.
我已经升级到最新的 node/npm/yarn/typescript 版本.也试过降级.没有任何帮助.
I already upgraded to the latest node/npm/yarn/typescript versions. Also tried downgrading. Nothing helps.
yarn build --verbose
yarn run v1.9.4
$ react-scripts-ts build --verbose
Creating an optimized production build...
Starting type checking and linting service...
Using 1 worker with 2048MB memory limit
ts-loader: Using typescript@3.0.3 and C:\dev\project\frontend\tsconfig.prod.json
Warning: member-ordering - Bad member kind: public-before-private
Failed to compile.
C:/dev/project/frontend/node_modules/@types/prop-types/node_modules/@types/react/index.d.ts
(2312,14): Duplicate identifier 'LibraryManagedAttributes'.
error Command failed with exit code 1.
--verbose
不知何故没有给我更多信息.
--verbose
somehow doesn't give me more information.
正如我所见,LibraryManagedAttributes
定义在:
As I can see LibraryManagedAttributes
is defined in:
node_modules/@types/react/index.d.ts
node_modules/@types/prop-types/node_modules/@types/react/index.d.ts
node_modules/@types/react-overlays/node_modules/@types/react/index.d.ts
- ....
这是从哪里来的?我怎样才能避免这种情况?
我想找出此错误的来源,以便我可以将其报告给正确的实体,但我不知道从哪里开始.
I want to find out where this error is coming from so that I can report it to the right entity but I don't know where to start.
我还能尝试什么?
推荐答案
这似乎是因为 Yarn 解析了一个包的多个版本;@types/react
在这种特殊情况下.Yarn 从 package.json 解析 @types/react
并作为 @types/react-dom
的依赖.
This seems te happen because Yarn resolves multiple versions of a package; @types/react
in this particular case. Yarn resolves @types/react
from your package.json and as a dependency of @types/react-dom
.
从我的 package.json 中获取以下代码片段:
Take the following snippet from my package.json:
"devDependencies": {
"@types/react": "^15.0.16",
"@types/react-dom": "^0.14.23"
...
}
在您运行 yarn install
后创建的 yarn.lock 包含类似以下内容:
The yarn.lock that is created after you run yarn install
contains something similar to this:
"@types/react-dom@^0.14.23":
version "0.14.23"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-0.14.23.tgz#cecfcfad754b4c2765fe5d29b81b301889ad6c2e"
dependencies:
"@types/react" "*"
"@types/react@*":
version "16.4.14"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.4.14.tgz#47c604c8e46ed674bbdf4aabf82b34b9041c6a04"
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"
"@types/react@^15.0.16":
version "15.6.19"
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.6.19.tgz#a5de18afe65b0f29767328836b48c498a5d3a91b"
请注意,@types/react-dom
依赖于 "*"
指示的任何版本的 @types/react
.Yarn 解析了 @types/react
的两个版本:"16.4.14"
和 "15.6.19"
.这会导致您提到的类型冲突.
Notice that @types/react-dom
depends on any version of @types/react
as indicated by "*"
. Yarn resolves two versions of @types/react
: "16.4.14"
and "15.6.19"
. This results in the type conflicts you mentioned.
解决方案是将 resolutions 字段添加到您的 resolutions 字段strong>package.json 告诉 Yarn 解析特定版本的 @types/react
.以以下示例为例:
The solution is to add a resolutions field to your package.json to tell Yarn to resolve a specific version of @types/react
. Take the following sample:
"resolutions": {
"@types/react": "^15.0.16"
}
再次运行yarn install
.请注意 yarn.lock 文件中的更改:
Run yarn install
again. Notice the change in the yarn.lock file:
"@types/react-dom@^0.14.23":
version "0.14.23"
resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-0.14.23.tgz#cecfcfad754b4c2765fe5d29b81b301889ad6c2e"
dependencies:
"@types/react" "*"
"@types/react@*", "@types/react@^15.0.16":
version "15.6.19"
resolved "https://registry.yarnpkg.com/@types/react/-/react-15.6.19.tgz#a5de18afe65b0f29767328836b48c498a5d3a91b"
Yarn 现在为 "@types/react@*"
和 "@types/react@^15.0 解析相同的版本
依赖项."15.6.19"
.16"
Yarn now resolves the same version "15.6.19"
for both "@types/react@*"
and "@types/react@^15.0.16"
dependencies.
我想知道自己为什么需要这样做.我希望 Yarn 能够理解它可以使用 "@types/react@^15.0.16"
解析依赖关系 "@types/react" "*"
而不是使用 "@types/react@^15.0.16"
解析它@types/react
的最新版本.
I would like to know myself why this is needed. I would expect Yarn to understand it can resolve dependency "@types/react" "*"
with "@types/react@^15.0.16"
instead of resolving it with the latest version of @types/react
.
这篇关于重复标识符“LibraryManagedAttributes"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!