首页 > 解决方案 > 未定义(未定义,未定义)中的 TypeScript 错误:找不到“组件发射器”的类型定义文件

问题描述

通过预定的 Microsoft 更新更新我的 Windows 10 后(我真的不知道这是否相关,也可能是巧合),我在运行yarn start.

undefined
TypeScript error in undefined(undefined,undefined):
Cannot find type definition file for 'component-emitter'.
  The file is in the program because:
    Entry point for implicit type library 'component-emitter'  TS2688
Failed to compile.

我发现了这个类似的帖子,它通过在 package.json 中删除一个名为 @types/ 的包来解决这个问题。但是我没有这样的包。

这是我的 package.json 文件:

{
  "name": "web-localizer",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@react-hook/window-size": "^3.0.7",
    "@unform/core": "^2.1.0",
    "@unform/web": "^2.1.0",
    "axios": "^0.19.2",
    "date-fns": "^2.14.0",
    "polished": "^3.5.2",
    "react": "^16.13.1",
    "react-dom": "^16.13.1",
    "react-icons": "^3.10.0",
    "react-map-gl": "^6.1.14",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.0",
    "react-spinners": "^0.9.0",
    "react-spring": "^8.0.27",
    "styled-components": "^5.1.0",
    "typescript": "^4.2.4",
    "uuidv4": "^6.0.8",
    "yup": "^0.28.5"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "test:coverage": "react-scripts test --coverage --watchAll false",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "jest": {
    "collectCoverageFrom": [
      "src/pages/**/*.tsx",
      "src/components/**/*.tsx",
      "src/hooks/*.tsx",
      "!src/hooks/intex.tsx"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/react-hooks": "^3.3.0",
    "@testing-library/user-event": "^7.1.2",
    "@types/jest": "^24.0.0",
    "@types/node": "^12.0.0",
    "@types/react": "^16.9.0",
    "@types/react-dom": "^16.9.0",
    "@types/react-router-dom": "^5.1.5",
    "@types/react-star-rating-component": "^1.4.0",
    "@types/styled-components": "^5.1.0",
    "@types/yup": "^0.28.0",
    "@typescript-eslint/eslint-plugin": "^2.29.0",
    "@typescript-eslint/parser": "^2.29.0",
    "axios-mock-adapter": "^1.18.1",
    "eslint": "^6.8.0",
    "eslint-config-airbnb": "^18.1.0",
    "eslint-config-prettier": "^6.11.0",
    "eslint-import-resolver-typescript": "^2.0.0",
    "eslint-plugin-import": "^2.20.2",
    "eslint-plugin-jsx-a11y": "^6.2.3",
    "eslint-plugin-prettier": "^3.1.3",
    "eslint-plugin-react": "^7.19.0",
    "eslint-plugin-react-hooks": "^2.5.1",
    "prettier": "^2.0.5"
  }
}

这是我的 tsconfig.json 文件:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react",
  },
  "include": [
    "src"
  ],
  "typeRoots": [
    "../node_modules/@types",
    "../@types"
  ]
}

我以前收到过这种警告,但现在我什至不能再构建 React 应用程序了。这让我无法工作,所以我有点绝望。如果有人知道这可能是什么,请尽快让我知道。我将提供任何可能需要的额外信息。

标签: reactjstypescript

解决方案


推荐阅读