web-dev-qa-db-ja.com

TypeScriptを使用したCRA 2.0は、実装の制限によりtsconfig.jsonをオーバーライドします

私はtailwindcssをセットアップして、真新しいCRA 2.0(具体的には2.1.2)内でTypeScriptを操作しようとしています。

「isolatedModules」をオーバーライドすることはできません:CRAがそれを上書きせずにtrueフラグ。

私は、modules.exportからエクスポートスタイルを変更し、configを削除する代わりにfalseに強制することで問題を回避しようとしました。別の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,
    "noEmit": true,
    "jsx": "preserve",
    "isolatedModules": true
  },
  "include": [
    "src",
    "postcss.config.js"
  ]
}

postcss.config.json

const tailwindcss = require('tailwindcss');
module.exports = {
  plugins: [tailwindcss('./tailwind.config.js'), require('autoprefixer')]
};

そして、これが私のnpmが吐き出すものです

The following changes are being made to your tsconfig.json file:
  - compilerOptions.isolatedModules must be true (implementation limitation)

アプリケーションがコンパイルされて動作し、ページにペイントされてから、赤いエラーボックスに置き換えられます。

Type error: Cannot compile namespaces when the '--isolatedModules' flag is 
provided.  TS1208

  > 1 | const tailwindcss = require('tailwindcss');
      | ^
    2 | module.exports = {
    3 |   plugins: [tailwindcss('./tailwind.config.js'), 
require('autoprefixer')]
    4 | };

Tsconfig.jsonをイジェクトまたは拡張せずに、アプリ全体で変更されたバージョンを使用せずに、これをオーバーライドするにはどうすればよいですか。

PDATE:アプリケーションをイジェクトし、webpack-configに直接行って分離モジュールフラグを削除することで、これを修正することができました。望んだ方法ではありませんが、機能します。

8
sanyangkkun

私はこれと同じものを得て、

// @ts-ignore 

requireを含む問題のあるステートメントの前に、それを修正しました。

イジェクトはこれに対するかなり抜本的な解決策です。推奨されません。

7