reactjs - File tsconfig saya tertimpa setiap kali saya menjalankan tes


Setiap kali saya menjalankan tes, file tsconfig.json saya akan tertimpa dan setelah tes berhasil, tes tersebut akan gagal dengan:

rpt2: config error TS6046: Argument for '--jsx' option must be: 'preserve', 'react-native', 'react'.
(rpt2 plugin) Error: /main/src/index.tsx(1,30): semantic error TS6142: Module './ExampleComponent' was resolved to '/main/src/ExampleComponent/index.tsx', but '--jsx' is not set.

Selama menjalankan kode, saya akan dimintai pesan:

The following changes are being made to your tsconfig.json file:
  - compilerOptions.allowJs to be suggested value: true (this can be changed)
  - compilerOptions.skipLibCheck to be suggested value: true (this can be changed)
  - compilerOptions.strict to be suggested value: true (this can be changed)
  - compilerOptions.forceConsistentCasingInFileNames to be suggested value: true (this can be changed)
  - compilerOptions.noFallthroughCasesInSwitch to be suggested value: true (this can be changed)
  - compilerOptions.resolveJsonModule must be true (to match webpack loader)
  - compilerOptions.isolatedModules must be true (implementation limitation)
  - compilerOptions.noEmit must be true
  - compilerOptions.jsx must be react-jsx (to support the new JSX transform in React 17)

Saya tahu ada banyak thread seperti itu, tetapi sejauh ini solusi di sana tidak membantu. Sejauh ini saya sudah mencoba:

  • Mengatur VSCode untuk menggunakan versi Typescript di workspace (4.3.5)
  • Mengubah parameter tsconfig.json (tetapi tidak peduli apa yang saya coba ubah di dalamnya akan ditimpa begitu saya menjalankan pengujian)
  • Memperbarui VSCode ke versi terbaru
  • memulai ulang server TS

Tsconfig asli saya:

{
  "compilerOptions": {
    "outDir": "dist",
    "module": "esnext",
    "lib": ["dom", "esnext"],
    "moduleResolution": "node",
    "jsx": "react",
    "sourceMap": true,
    "declaration": true,
    "esModuleInterop": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "allowSyntheticDefaultImports": true,
    "target": "es5",
    "types": ["webrtc"]
  },
  "include": ["src"],
  "exclude": ["node_modules", "dist"]
}

Dan setelah saya menjalankan tes:

{
  "compilerOptions": {
    "outDir": "dist",
    "module": "esnext",
    "lib": [
      "dom",
      "esnext"
    ],
    "moduleResolution": "node",
    "jsx": "react-jsx",
    "sourceMap": true,
    "declaration": true,
    "esModuleInterop": true,
    "noImplicitReturns": true,
    "noImplicitThis": true,
    "noImplicitAny": true,
    "strictNullChecks": true,
    "suppressImplicitAnyIndexErrors": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "allowSyntheticDefaultImports": true,
    "target": "es5",
    "types": [
      "webrtc"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true
  },
  "include": [
    "src"
  ],
  "exclude": [
    "node_modules",
    "dist"
  ]
}

Saya juga mendapatkan file react-app-env.d.ts yang dihasilkan dengan:

/// <reference types="react-scripts" />

Dan settings.json dengan:

{
  "typescript.tsdk": "node_modules/typescript/lib"
}

Saya menggunakan:

  • typescript 4.3.5
  • react-scripts 4.0.3
  • react 17.0.2