創(chuàng)建React Native的第一個hello world工程
需要安裝好node、npm環(huán)境
如果之前沒有安裝過react-native-cli
腳手架的,可以按照下述步驟直接安裝。如果已經(jīng)安裝過的,但是在使用這個腳手架初始化工程的時候遇到下述報錯的話
cli.init(root, projectname);
^
typeerror: cli.init is not a function
at run (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:302:7)
at createproject (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:249:3)
at init (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:200:5)
at object.<anonymous> (c:\users\showbi\appdata\roaming\npm\node_modules\react-native-cli\index.js:153:7)
at module._compile (node:internal/modules/cjs/loader:1105:14)
at object.module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at module.load (node:internal/modules/cjs/loader:981:32)
at function.module._load (node:internal/modules/cjs/loader:822:12)
at function.executeuserentrypoint [as runmain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47
也可以先直接卸載
npm uninstall -g react-native-cli
正常安裝過程:
- 安裝
react-native-cli
npm install -g react-native-cli
- 安裝
react-native
npm install -g react-native
安裝完成之后,可以用腳手架來初始化項目
npx react-native init firstRNProject
就會出現(xiàn)下述的界面
安裝編譯到Android手機上去
react-native run-android
啟動以后的界面如下所示:
文章來源:http://www.zghlxwxcb.cn/news/detail-723254.html
在這個過程中可能會遇到一些版本帶來的問題,文章來源地址http://www.zghlxwxcb.cn/news/detail-723254.html
- 比如0.69的版本時候,會遇到上述腳手架初始化的時候報錯,參考 https://github.com/facebook/react-native/issues/34055
npx react-native init ProjectName --version 0.68.2
選擇其他版本解決 - ruby版本和gem版本不匹配的時候,報錯日志信息
Your Ruby version is 3.1.2, but your Gemfile specified 2.7.5
參考 https://github.com/facebook/react-native/issues/35127 - 啟動后報錯提示報錯信息如下
參考https://github.com/facebook/react-native/issues/21530,清除緩存重新npm install安裝新的依賴包解決react-native start --reset-cache
react-native run-android
到了這里,關于創(chuàng)建React Native的第一個hello world工程的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!