create-react-app 遇到问题 TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'

问题

提示:这个 Bug 可能会随版本更新而消失。

使用 yarn create react-app my-app --template typescript 后,执行 yarn start 时出现的错误。

yarn run v1.22.5
$ react-scripts start
C:\Users\Liang\Desktop\Project\i-show-you\webapp\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:239
      appTsConfig.compilerOptions[option] = value;
                                          ^

TypeError: Cannot assign to read only property 'jsx' of object '#<Object>'
    at verifyTypeScriptSetup (C:\Users\Liang\Desktop\Project\i-show-you\webapp\node_modules\react-scripts\scripts\utils\verifyTypeScriptSetup.js:239:43)
    at Object.<anonymous> (C:\Users\Liang\Desktop\Project\i-show-you\webapp\node_modules\react-scripts\scripts\start.js:31:1)
    at Module._compile (internal/modules/cjs/loader.js:1063:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
    at Module.load (internal/modules/cjs/loader.js:928:32)
    at Function.Module._load (internal/modules/cjs/loader.js:769:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

参考

在 GitHub Issue 中找到参考:TypeError: Cannot assign to read only property 'jsx' of object '#<Object>' · Issue #10110 · facebook/create-react-app

原因

可能与 tsconfig.json 中的设置有关。

解决方案

其中的一种解决方案如下,需要依次执行下面三条命令:

yarn add typescript@4.0.5
rm tsconfig.json
yarn start

如果你用的是 Windows 的话,可能在第二步,要手动删除一下 tsconfig.json 文件。

其他解决方案可以参考上面的 Issue。

posted on 2020-11-22 18:17  atLFN  阅读(1363)  评论(0编辑  收藏  举报