create-react-app 遇到问题 TypeError: Cannot assign to read only property 'jsx' of 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。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' 解决 Cannot assign to read only property 'exports' of object '#' 问题 Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue的报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object '#' Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法 关于vue-cli3打包时遇到Cannot assign to read only property 'exports' of object '#'问题的解决方法。 Cannot assign to read only property 'exports' of object '#' Cannot assign to read only property 'exports' of object '#' Vue报错:Uncaught TypeError: Cannot assign to read only property 'exports' of object 的解决方法
 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM