【React1】創(chuàng)建單頁應用

Create React App 腳手架工具要门,是創(chuàng)建React項目的最佳方式拟淮。

創(chuàng)建項目前要滿足 Node >= 8.10npm >= 5.6捕透。
如何安裝和使用React腳手架

npm install -g create-react-app
cd Desktop

npx create-react-app my-app
cd my-app
npm start

npm install -g create-react-app 安裝腳手架
重啟項目時運行 npm run start也可以是 npm start
項目名稱菇爪,必須為小寫字母 my-app

項目創(chuàng)建成功

報錯信息如下:

$ react-scripts start

There might be a problem with the project dependency tree.
It is likely not a bug in Create React App, but something you need to fix locally.

The react-scripts package provided by Create React App requires a dependency:

“webpack”: “4.19.1”

Don’t try to install it manually: your package manager does it automatically.
However, a different version of webpack was detected higher up in the tree:

/Users/apple/node_modules/webpack (version: 4.28.2)

Manually installing incompatible versions is known to cause hard-to-debug issues.

If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove “webpack” from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use.

In most cases, this should be enough to fix the problem.
If this has not helped, there are a few other things you can try:

  1. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead.
    This may help because npm has known issues with package hoisting which may get resolved in future versions.

  2. Check if /Users/apple/node_modules/webpack is outside your project directory.
    For example, you might have accidentally installed something in your home folder.

  3. Try running npm ls webpack in your project folder.
    This will tell you which other package (apart from the expected react-scripts) installed webpack.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project.
That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above ?? We hope you find them helpful!

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

解決問題思路:

創(chuàng)建一個 .env 文件 SKIP_PREFLIGHT_CHECK=true 添加這句代碼唠梨,在終端輸入npm start重啟就好了袋励。

下圖參考圖:

2019010119564687.png
最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子茬故,更是在濱河造成了極大的恐慌盖灸,老刑警劉巖,帶你破解...
    沈念sama閱讀 222,183評論 6 516
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件磺芭,死亡現(xiàn)場離奇詭異赁炎,居然都是意外死亡,警方通過查閱死者的電腦和手機钾腺,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,850評論 3 399
  • 文/潘曉璐 我一進店門徙垫,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人放棒,你說我怎么就攤上這事姻报。” “怎么了间螟?”我有些...
    開封第一講書人閱讀 168,766評論 0 361
  • 文/不壞的土叔 我叫張陵吴旋,是天一觀的道長。 經(jīng)常有香客問我厢破,道長荣瑟,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,854評論 1 299
  • 正文 為了忘掉前任摩泪,我火速辦了婚禮褂傀,結果婚禮上,老公的妹妹穿的比我還像新娘加勤。我一直安慰自己仙辟,他們只是感情好,可當我...
    茶點故事閱讀 68,871評論 6 398
  • 文/花漫 我一把揭開白布鳄梅。 她就那樣靜靜地躺著叠国,像睡著了一般。 火紅的嫁衣襯著肌膚如雪戴尸。 梳的紋絲不亂的頭發(fā)上粟焊,一...
    開封第一講書人閱讀 52,457評論 1 311
  • 那天,我揣著相機與錄音孙蒙,去河邊找鬼项棠。 笑死,一個胖子當著我的面吹牛挎峦,可吹牛的內(nèi)容都是我干的香追。 我是一名探鬼主播,決...
    沈念sama閱讀 40,999評論 3 422
  • 文/蒼蘭香墨 我猛地睜開眼坦胶,長吁一口氣:“原來是場噩夢啊……” “哼透典!你這毒婦竟也來了晴楔?” 一聲冷哼從身側響起,我...
    開封第一講書人閱讀 39,914評論 0 277
  • 序言:老撾萬榮一對情侶失蹤峭咒,失蹤者是張志新(化名)和其女友劉穎税弃,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體凑队,經(jīng)...
    沈念sama閱讀 46,465評論 1 319
  • 正文 獨居荒郊野嶺守林人離奇死亡则果,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 38,543評論 3 342
  • 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了漩氨。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片短条。...
    茶點故事閱讀 40,675評論 1 353
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖才菠,靈堂內(nèi)的尸體忽然破棺而出茸时,到底是詐尸還是另有隱情,我是刑警寧澤赋访,帶...
    沈念sama閱讀 36,354評論 5 351
  • 正文 年R本政府宣布可都,位于F島的核電站,受9級特大地震影響蚓耽,放射性物質(zhì)發(fā)生泄漏渠牲。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 42,029評論 3 335
  • 文/蒙蒙 一步悠、第九天 我趴在偏房一處隱蔽的房頂上張望签杈。 院中可真熱鬧,春花似錦鼎兽、人聲如沸答姥。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,514評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽鹦付。三九已至,卻和暖如春择卦,著一層夾襖步出監(jiān)牢的瞬間敲长,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,616評論 1 274
  • 我被黑心中介騙來泰國打工秉继, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留祈噪,地道東北人。 一個月前我還...
    沈念sama閱讀 49,091評論 3 378
  • 正文 我出身青樓尚辑,卻偏偏與公主長得像辑鲤,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子腌巾,可洞房花燭夜當晚...
    茶點故事閱讀 45,685評論 2 360