gpt4 book ai didi

reactjs - 类型错误 : Cannot assign to read only property 'paths' of object for compilerOptions in tsconfig

转载 作者:行者123 更新时间:2023-12-03 15:27:09 24 4
gpt4 key购买 nike

**Trying to set the path inside tsconfig.json for compiler to treat src as baseUrl in react typescript project**

{
"compilerOptions": {
"target": "es5",
"baseUrl": "src",
"paths": {
"*": ["src/*"]
}
"include": [
"src"
]
}
但得到如下错误:
TypeError: Cannot assign to read only property 'paths' of object '#<Object>'
at verifyTypeScriptSetup (/Users/apple/Documents/projects/my-app/node_modules/react-scripts/scripts/utils/verifyTypeScriptSetup.js:239:43)
这是因为文件夹权限还是配置中缺少任何内容

最佳答案

显然,有一个 bug在 Create-React-App@4.0.0 中。
为我解决的解决方法是:
降级 react-scripts :

yarn add react-scripts@3.4.4
创建一个 paths.json在项目的根目录中:
{
"compilerOptions": {
"baseUrl": "./src",
"paths": {
"@Components/*": ["components/*"]
}
}
}
添加 extendstsconfig.json :
{
"extends": "./paths.json",
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react"
},
"include": [
"src"
]
}

关于reactjs - 类型错误 : Cannot assign to read only property 'paths' of object for compilerOptions in tsconfig,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64593336/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com