tsconfig noEmit 必须为真

Bre*_*ent 5 typescript create-react-app

我正在使用 create-react-app 并且我还有一些 ts 和 tsx 文件。在我的 tsconfig 文件(见下文)中,我将 noEmit 设置为 false,因为需要发出 js 文件。但是,每次启动服务器时, noEmit 都会设置为 false 并显示以下消息:

The following changes are being made to your tsconfig.json file:
   - compilerOptions.noEmit must be true
Run Code Online (Sandbox Code Playgroud)

当 noEmit 设置为 false 时,应该从我的 ts 文件生成的 js 文件不会生成,这意味着应用程序没有更新。是什么导致了这种行为?有什么办法可以避免吗?或者是为包含 ts 文件的文件夹制作单独的 tsconfig 的唯一选择?

{
  "compilerOptions": {
    "target": "ES2017",
    "module": "esnext",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext",
      "ES2017"
    ],
    "allowJs": false,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "strictPropertyInitialization": false,
    "strictNullChecks": false,
    "strict": true,
    "sourceMap": true,
    "noEmit": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules"
  ]
}
Run Code Online (Sandbox Code Playgroud)

小智 3

您需要在 webpack.config 文件中覆盖此编译选项,如下所示:

rules: [
     {
        test: /\.tsx?$/,
        loader: 'ts-loader',
        options: {
           compilerOptions: {
              "noEmit": false
           }
        },
        exclude: /node_modules/,
      },
Run Code Online (Sandbox Code Playgroud)

  • 我认为使用 CRA 你不能编辑 webpack.config?这让我发疯 (2认同)