Reactjs 由于实现限制,CRA 2.0 w/typescript会覆盖my tsconfig.json
我正在尝试在全新的CRA2.0(特别是2.1.2)中使用tailwindcss设置和typescript 我无法覆盖“isolatedModules”:如果CRA不覆盖它,则无法覆盖true标志 我试图通过从modules.export更改导出样式并强制将配置设置为false而不是删除它来绕过这个问题。我了解到,您还可以创建一个单独的tsconfig.json,扩展旧的tsconfig.json,并覆盖其中的更改,但这似乎有点老套 tsconfig.jsonReactjs 由于实现限制,CRA 2.0 w/typescript会覆盖my tsconfig.json,reactjs,typescript,create-react-app,tailwind-css,Reactjs,Typescript,Create React App,Tailwind Css,我正在尝试在全新的CRA2.0(特别是2.1.2)中使用tailwindcss设置和typescript 我无法覆盖“isolatedModules”:如果CRA不覆盖它,则无法覆盖true标志 我试图通过从modules.export更改导出样式并强制将配置设置为false而不是删除它来绕过这个问题。我了解到,您还可以创建一个单独的tsconfig.json,扩展旧的tsconfig.json,并覆盖其中的更改,但这似乎有点老套 tsconfig.json { "compilerOptio
{
"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"
]
}
const tailwindcss = require('tailwindcss');
module.exports = {
plugins: [tailwindcss('./tailwind.config.js'), require('autoprefixer')]
};
postss.config.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"
]
}
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并在整个应用程序中使用修改后的版本的情况下覆盖此选项
更新:我可以通过弹出我的应用程序并直接进入网页包配置来删除isolatedModules标志来解决这个问题,这不是我想要的方式,但它是有效的。我得到了同样的结果,并添加了一个
// @ts-ignore
在带有require的冒犯性语句之前,该语句已修复
弹射是解决这个问题的一个相当激烈的方法;不推荐。这是我的解决方案,因为每次运行应用程序时,如果
isolatedModules
为false
,应用程序会将其重新写入true
,并引用某种错误:正在对tsconfig.json文件进行以下更改:-编译器选项.isolatedModules必须为true(实现限制)
当我尝试使用TypeScript和Jest时发生了这种情况。在我的Jest文件顶部添加了/@ts ignore
,问题就消失了。