初試React(基于homebrew1.8.6、node11.6.0辰晕、npm6.5.0蛤迎、cnpm6.0.0)

一、開發(fā)環(huán)境搭建

1含友、更新brew

    命令:
    brew update
    解釋:
    更新brew的所有本地包

2替裆、安裝/更新node

    命令:
    brew install node
    brew upgrade node
    解釋:
    安裝node
    更新node

3校辩、安裝cnpm

    命令:
    npm install -g cnpm --registry=https://registry.npm.taobao.org
    解釋:
    npm install[安裝命令] -g[全局安裝參數(shù)] cnpm[cnpm包名稱] --registry[指定cnpm軟件包源] = https://registry.npm.taobao.org[cnpm軟件包源地址]

4、安裝webpack

    命令
    cnpm install webpack
    解釋:
    cnpm install[安裝命令] webpack[軟件包名]

5辆童、安裝create-react-app

    命令:
    cnpm install create-react-app
    解釋:
    cnpm install[安裝命令] create-react-app[軟件包名]

6宜咒、安裝babel-loader

    命令:
    cnpm install babel-loader@8.0.4
    解釋:
    cnpm install[安裝命令] babel-loader@8.0.4 [軟件包名@版本號](版本號為可選參數(shù),不添加則自動下載最新版本)

7把鉴、安裝react

    命令:
    cnpm install react
    解釋:
    cnpm install [安裝命令] react[軟件包名]

8故黑、安裝react-dom

    命令:
    cnpm install react-dom
    解釋:
    cnpm install[安裝命令] react-dom[軟件包名]

二、創(chuàng)建第一個react工程

1庭砍、創(chuàng)建基礎(chǔ)工程

    命令:
    create-react-app helloworld
    解釋:
    使用create-react-app創(chuàng)建一個名為helloworld的工程目錄

2场晶、拿出一包咖啡泡上

    命令:
    別放糖,少放奶
    解釋:
    解釋怠缸?解釋什么诗轻?會下載很多東西,喝杯咖啡等著就行了

3揭北、沒了

三扳炬、運(yùn)行helloworld

1、進(jìn)入helloworld工程目錄搔体,啟動工程

    命令:
    cd helloworld
    npm start
    解釋:
    進(jìn)入helloworld工程目錄
    啟動工程

2恨樟、查看運(yùn)行效果

    瀏覽器輸入http://localhost:3000
    若正常啟動瀏覽器將顯示一個react頁面

四、坑

1疚俱、Q:npm start執(zhí)行失敗劝术,日志如下

  [@Freedoms:helloworld (master)]$ npm start
  > helloworld@0.1.0 start /Users/freedoms/work/react/helloworld
  > 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:
    "babel-loader": "8.0.4"
  Don't try to install it manually: your package manager does it automatically.
  However, a different version of babel-loader was detected higher up in the tree:
    /Users/freedoms/work/react/helloworld/node_modules/babel-loader (version: 8.0.5)
  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 "babel-loader" 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:
    5. 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.
    6. Check if /Users/freedoms/work/react/helloworld/node_modules/babel-loader is outside your project directory.
    For example, you might have accidentally installed something in your home folder.
    7. Try running npm ls babel-loader in your project folder.
     This will tell you which other package (apart from the expected react-scripts) installed babel-loader.
  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!
  npm ERR! code ELIFECYCLE
  npm ERR! errno 1
  npm ERR! helloworld@0.1.0 start: `react-scripts start`
  npm ERR! Exit status 1
  npm ERR!
  npm ERR! Failed at the helloworld@0.1.0 start script.
  npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  npm ERR! A complete log of this run can be found in:
  npm ERR!     /Users/freedoms/.npm/_logs/2019-01-21T16_16_39_054Z-debug.log
A:解決辦法
  1、卸載babel-loader
  2计螺、指定安裝babel-loader版本8.0.4
  3夯尽、重新執(zhí)行npm start
  4、坑已填好

五登馒、參考

1匙握、淘寶npm鏡像 http://npm.taobao.org/
2、React 中文文檔 https://react.docschina.org/
3陈轿、React China http://react-china.org/
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末圈纺,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子麦射,更是在濱河造成了極大的恐慌蛾娶,老刑警劉巖,帶你破解...
    沈念sama閱讀 223,126評論 6 520
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件潜秋,死亡現(xiàn)場離奇詭異蛔琅,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)峻呛,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 95,421評論 3 400
  • 文/潘曉璐 我一進(jìn)店門罗售,熙熙樓的掌柜王于貴愁眉苦臉地迎上來辜窑,“玉大人,你說我怎么就攤上這事寨躁∧滤椋” “怎么了?”我有些...
    開封第一講書人閱讀 169,941評論 0 366
  • 文/不壞的土叔 我叫張陵职恳,是天一觀的道長所禀。 經(jīng)常有香客問我,道長放钦,這世上最難降的妖魔是什么色徘? 我笑而不...
    開封第一講書人閱讀 60,294評論 1 300
  • 正文 為了忘掉前任,我火速辦了婚禮操禀,結(jié)果婚禮上贺氓,老公的妹妹穿的比我還像新娘。我一直安慰自己床蜘,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 69,295評論 6 398
  • 文/花漫 我一把揭開白布蔑水。 她就那樣靜靜地躺著邢锯,像睡著了一般。 火紅的嫁衣襯著肌膚如雪搀别。 梳的紋絲不亂的頭發(fā)上丹擎,一...
    開封第一講書人閱讀 52,874評論 1 314
  • 那天,我揣著相機(jī)與錄音歇父,去河邊找鬼蒂培。 笑死,一個胖子當(dāng)著我的面吹牛榜苫,可吹牛的內(nèi)容都是我干的护戳。 我是一名探鬼主播,決...
    沈念sama閱讀 41,285評論 3 424
  • 文/蒼蘭香墨 我猛地睜開眼垂睬,長吁一口氣:“原來是場噩夢啊……” “哼媳荒!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起驹饺,我...
    開封第一講書人閱讀 40,249評論 0 277
  • 序言:老撾萬榮一對情侶失蹤钳枕,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后赏壹,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體鱼炒,經(jīng)...
    沈念sama閱讀 46,760評論 1 321
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,840評論 3 343
  • 正文 我和宋清朗相戀三年蝌借,在試婚紗的時候發(fā)現(xiàn)自己被綠了昔瞧。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片指蚁。...
    茶點(diǎn)故事閱讀 40,973評論 1 354
  • 序言:一個原本活蹦亂跳的男人離奇死亡,死狀恐怖硬爆,靈堂內(nèi)的尸體忽然破棺而出欣舵,到底是詐尸還是另有隱情,我是刑警寧澤缀磕,帶...
    沈念sama閱讀 36,631評論 5 351
  • 正文 年R本政府宣布缘圈,位于F島的核電站,受9級特大地震影響袜蚕,放射性物質(zhì)發(fā)生泄漏糟把。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 42,315評論 3 336
  • 文/蒙蒙 一牲剃、第九天 我趴在偏房一處隱蔽的房頂上張望遣疯。 院中可真熱鬧,春花似錦凿傅、人聲如沸缠犀。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,797評論 0 25
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽辨液。三九已至,卻和暖如春箱残,著一層夾襖步出監(jiān)牢的瞬間滔迈,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,926評論 1 275
  • 我被黑心中介騙來泰國打工被辑, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留燎悍,地道東北人。 一個月前我還...
    沈念sama閱讀 49,431評論 3 379
  • 正文 我出身青樓盼理,卻偏偏與公主長得像谈山,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子宏怔,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,982評論 2 361

推薦閱讀更多精彩內(nèi)容

  • 1 Webpack 1.1 概念簡介 1.1.1 WebPack是什么 1勾哩、一個打包工具 2、一個模塊加載工具 3...
    Kevin_Junbaozi閱讀 6,680評論 0 16
  • 寫在前面的話 閱讀本文之前举哟,先看下面這個webpack的配置文件思劳,如果每一項你都懂,那本文能帶給你的收獲也許就比較...
    不忘初心_9a16閱讀 3,242評論 0 17
  • 版權(quán)聲明:本文為博主原創(chuàng)文章威兜,未經(jīng)博主允許不得轉(zhuǎn)載销斟。 webpack介紹和使用 一、webpack介紹 1椒舵、由來 ...
    it筱竹閱讀 11,166評論 0 21
  • 不能給你未來蚂踊,我還你現(xiàn)在,安靜結(jié)束也是另一種對待笔宿。再回首犁钟,那看似浪漫的劇情現(xiàn)在看來也是一場鬧劇,原來我們每個人都喜...
    瑾沉閱讀 815評論 0 1
  • 凌晨一點(diǎn)多時候泼橘,外邊呼呼的大風(fēng)開始刮起來涝动,越刮越大,聽著房屋聲音嘩啦啦炬灭,似乎屋頂都要被掀翻一樣醋粟。過了一會兒就開始下...
    XuhongZhai閱讀 145評論 0 0