我使用了以下命令:
npx create-react-app fresh-cra && cd fresh-cra
創建一個Create React App (CRA)的新副本。
但是當我按照命令后面的說明運行時
,npm test它給了我一個錯誤:npx create-react-app
● Test suite failed to run
令人沮喪的是,沒有關于該錯誤的其他資訊。

^ 點擊放大
我該如何解決這個錯誤?
在互聯網上搜索了幾天后,我終于找到了
來自 create-react-app 的問題 Jest not running on Windows,它似乎報告了完全相同的錯誤,但適用于 Windows 8.1。
(我使用的是 Windows 10,版本 21H2。)
就像問這個問題的人一樣,我很困惑。不僅是錯誤,而且是從那時起經過的時間。三年多之后,同樣的錯誤仍然盛行,真的嗎? Create React App 團隊中沒有任何人修復這個錯誤? 1
不要誤會我的意思。我是create-react-app npm 包的忠實粉絲。
例如,eslint-config-react-app npm 包
已被證明非常有用。
但如果這是一個僅限 Windows 的錯誤,老實說,我不禁為在 Windows 上而感到有點被欺負。
npm test
在新的 Create React App 上運行時,Linux 或 macOS 上的任何人都會遇到同樣的錯誤
嗎?
Support for the experimental syntax 'jsx' isn't currently enabled
既然npm test不行,就覺得直接運行Jest的傾向,于是試了一下npx jest命令。
2

但后來我讀到了這個答案
——據我所知——它指出 Create React App 沒有開箱即用地配置來運行jest命令。
所以這顯然是一條我不想走的死胡同。
參考
- 創建 React 應用程式 (CRA)
- 來自 create-react-app 的玩笑不在 Windows 上運行
- create-react-app npm 包
- eslint-config-react-app npm 包
- 令人愉快的 JavaScript 測驗
- 在不在 Windows 上運行的 Create React App 上回答Jest
1 還是Jest團隊達不到標準?
2來自 create-react-app not running on Windows 的 Jest 提問者也是 如此。
uj5u.com熱心網友回復:
我該如何解決這個錯誤?
令人驚訝的是,它非常簡單。
在package.json檔案中,只需替換
"test": "react-scripts test",
和
"test": "react-scripts test --watchAll",
當您現在運行時npm test,期望看到:

沒有錯誤!
參考
- 在不在 Windows 上運行的 Create React App 上回答Jest
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/483819.html
