首页 > 解决方案 > 如何将 react-app-rewired 与 TypeScript 一起使用?

问题描述

以下 StackOverflow 答案告诉我如何使用 react-app-rewired 从src文件夹外部导入 JavaScript 文件,而不弹出应用程序:

https://stackoverflow.com/a/55298684/377011

但是,当将它与文件夹之外的 Typescript 文件一起使用时src(即import * from '../../myfile.ts'),我收到以下错误:

Module not found: Can't resolve 'ts-loader' in '...\myapp'

所以我安装了ts-loaderyarn add ts-loader),但现在我得到了

Error: TypeScript emitted no output for ...\myapp\src\index.tsx

noEmittrue我的tsconfig.json.

任何想法?

编辑:这是我的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"
  ]
}

标签: javascriptreactjstypescriptwebpackcreate-react-app

解决方案


推荐阅读