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