Help us understand the problem. What is going on with this article?

[TypeScript] tsc が "error TS2300: Duplicate identifier 'FormData'." でコケる

エラーメッセージ全体

console
$ ./node_modules/.bin/tsc
node_modules/@types/react-native/globals.d.ts:40:15 \
- error TS2300: Duplicate identifier 'FormData'.

40 declare class FormData {
                 ~~~~~~~~

  node_modules/typescript/lib/lib.dom.d.ts:5657:11
    5657 interface FormData {
                   ~~~~~~~~
    'FormData' was also declared here.
  node_modules/typescript/lib/lib.dom.d.ts:5667:13
    5667 declare var FormData: {
                     ~~~~~~~~
    and here.

結論

tsconfig.json
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "es2019",
      "dom"
    ],
    "module": "commonjs",
    "declaration": true,
    "strict": true,
    "esModuleInterop": true,
    "outDir": "./lib/",
    "sourceMap": false,
+    "types": ["react"],
    "jsx": "react"
  }

原因?

  • @types/react-native は入れた覚えがない(web向けの単なるreactアプリである)
  • どのパッケージがこれを引っ張ってきたの?
bash
$ yarn why @types/react-native
yarn why v1.19.1
[1/4] 🤔  Why do we have the module "@types/react-native"...?
[2/4] 🚚  Initialising dependency graph...
[3/4] 🔍  Finding dependency...
[4/4] 🚡  Calculating file sizes...
=> Found "@types/react-native@0.60.22"
info Reasons this module exists
   - "@types#styled-components" depends on it
   - Hoisted from "@types#styled-components#@types#react-native"

styled-components(の型定義ファイル)が犯人でした。

何をつくってたの?(宣伝)

はじめて npm パッケージをリリースしてみました。

コンテナサイズに合わせて画像を表示し、ズーム&パンを可能にするだけの React ライブラリです。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした