Я пытаюсь написать компонент React (с TS) как независимый пакет, используемый другим моим проектом.На данный момент я использую Verdaccio, установленный на локальном NAS для размещения своих пакетов, и эта часть работает хорошо.
Моя проблема в том, что когда я пытаюсь скомпилировать свой компонент (довольно просто), TypeScript дает мне чертовски много проблем впечатаю файлы.
Мой компонент использует только компоненты React и Styled, а также другой из моих пакетов (который сам использует только React и правильно компилируется).В VS Code у меня нет ни одной ошибки или предупреждения.
Вот ошибки, которые я получаю при запуске tsc
:
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(5196,11): error TS2300: Duplicate identifier 'FormData'.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(5206,13): error TS2300: Duplicate identifier 'FormData'.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(16513,11): error TS2320: Interface 'Window' cannot simultaneously extend types 'GlobalFetch' and 'WindowOrWorkerGlobalScope'.
Named property 'fetch' of types 'GlobalFetch' and 'WindowOrWorkerGlobalScope' are not identical.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(17406,13): error TS2451: Cannot redeclare block-scoped variable 'navigator'.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(17510,13): error TS2451: Cannot redeclare block-scoped variable 'console'.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(17819,6): error TS2300: Duplicate identifier 'RequestInfo'.
../../../../../.npm-global/lib/node_modules/typescript/lib/lib.dom.d.ts(17992,6): error TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.
node_modules/@types/react-native/globals.d.ts(36,15): error TS2300: Duplicate identifier 'FormData'.
node_modules/@types/react-native/globals.d.ts(81,5): error TS2717: Subsequent property declarations must have the same type. Property 'body' must be of type 'string | ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | null | undefined', but here has type 'string | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | Blob | FormData | null | undefined'.
node_modules/@types/react-native/globals.d.ts(107,14): error TS2300: Duplicate identifier 'RequestInfo'.
node_modules/@types/react-native/globals.d.ts(126,13): error TS2403: Subsequent variable declarations must have the same type. Variable 'Response' must be of type '{ new (body?: string | ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | ReadableStream<Uint8Array> | null | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error(): Response; redirect(url: string, status?: number | undefined): Response; }', but here has type '{ new (body?: string | ArrayBuffer | DataView | Int8Array | Uint8Array | Uint8ClampedArray | Int16Array | Uint16Array | Int32Array | Uint32Array | Float32Array | Float64Array | Blob | FormData | null | undefined, init?: ResponseInit | undefined): Response; prototype: Response; error: () => Response; redirect: (url: ...'.
node_modules/@types/react-native/globals.d.ts(196,5): error TS2717: Subsequent property declarations must have the same type. Property 'abort' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(197,5): error TS2717: Subsequent property declarations must have the same type. Property 'error' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(198,5): error TS2717: Subsequent property declarations must have the same type. Property 'load' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(199,5): error TS2717: Subsequent property declarations must have the same type. Property 'loadend' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(200,5): error TS2717: Subsequent property declarations must have the same type. Property 'loadstart' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(201,5): error TS2717: Subsequent property declarations must have the same type. Property 'progress' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(202,5): error TS2717: Subsequent property declarations must have the same type. Property 'timeout' must be of type 'ProgressEvent', but here has type 'Event'.
node_modules/@types/react-native/globals.d.ts(206,5): error TS2717: Subsequent property declarations must have the same type. Property 'onabort' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(207,5): error TS2717: Subsequent property declarations must have the same type. Property 'onerror' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(208,5): error TS2717: Subsequent property declarations must have the same type. Property 'onload' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(209,5): error TS2717: Subsequent property declarations must have the same type. Property 'onloadend' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(210,5): error TS2717: Subsequent property declarations must have the same type. Property 'onloadstart' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(211,5): error TS2717: Subsequent property declarations must have the same type. Property 'onprogress' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(212,5): error TS2717: Subsequent property declarations must have the same type. Property 'ontimeout' must be of type '((this: XMLHttpRequest, ev: ProgressEvent) => any) | null', but here has type '((this: XMLHttpRequest, ev: Event) => any) | null'.
node_modules/@types/react-native/globals.d.ts(243,6): error TS2300: Duplicate identifier 'XMLHttpRequestResponseType'.
node_modules/@types/react-native/index.d.ts(3838,49): error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
node_modules/@types/react-native/index.d.ts(3859,42): error TS2583: Cannot find name 'Map'. Do you need to change your target library? Try changing the `lib` compiler option to es2015 or later.
node_modules/@types/react-native/index.d.ts(9318,11): error TS2451: Cannot redeclare block-scoped variable 'console'.
node_modules/@types/react-native/index.d.ts(9326,18): error TS2717: Subsequent property declarations must have the same type. Property 'geolocation' must be of type 'Geolocation', but here has type 'GeolocationStatic'.
node_modules/@types/react-native/index.d.ts(9329,11): error TS2451: Cannot redeclare block-scoped variable 'navigator'.
Вот мои tsconfig.json
:
{
"compilerOptions": {
"outDir": "./lib",
"declaration": true,
"target": "es5",
"jsx": "react",
"strict": true,
"forceConsistentCasingInFileNames": true
},
"include": [
"src"
],
"exclude": [
"node_modules"
]
}
И мой package.json
:
{
"name": "@hpi_components/card",
"version": "1.0.4",
"main": "./lib/index.js",
"types": "./lib/index.d.ts",
"publishConfig": {
"registry": "http://10.0.0.102:32768"
},
"dependencies": {
"@hpi_components/application_theme_context": "^1.0.8",
"@types/react": "^16.8.3",
"@types/styled-components": "^4.1.10",
"react": "^16.8.2",
"react-dom": "^16.8.2",
"styled-components": "^4.1.3"
}
}
Понятия не имею, почему у меня возникают эти проблемы, в основном, почему упоминаются реакции на родную ...
Спасибоза вашу помощь!