san*_*kun 8 typescript reactjs create-react-app tailwind-css
我正在尝试安装tailwindcss并在全新的CRA 2.0(特别是2.1.2)中使用打字稿。
我无法在没有CRA覆盖的情况下覆盖“ isolatedModules”:true标志。
我尝试通过从modules.export更改导出样式并将配置强制为false而不是删除它来解决此问题。我读到,您还可以创建一个单独的tsconfig.json,扩展您的旧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"
]
}
Run Code Online (Sandbox Code Playgroud)
postcss.config.json
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [tailwindcss('./tailwind.config.js'), require('autoprefixer')]
};
Run Code Online (Sandbox Code Playgroud)
这是我的npm开始吐出来的东西
The following changes are being made to your tsconfig.json file:
- compilerOptions.isolatedModules must be true (implementation limitation)
Run Code Online (Sandbox Code Playgroud)
我可以看到我的应用程序可以编译,工作,然后绘制到页面上,然后将其替换为显示错误的红色错误框
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 | };
Run Code Online (Sandbox Code Playgroud)
如何在不弹出或扩展tsconfig.json并在整个应用程序中使用修改后的版本的情况下覆盖此内容。
更新:我能够通过弹出应用程序并直接进入webpack-config来删除isolatedModules标志来解决此问题,这不是我想要的方式,但是它可以工作。
我得到了同样的东西,并添加了一个
// @ts-ignore
Run Code Online (Sandbox Code Playgroud)
在带有require的有问题的声明之前,并对其进行了修复。
弹出是解决此问题的非常有效的方法。不建议。
| 归档时间: |
|
| 查看次数: |
1786 次 |
| 最近记录: |