1. 程式人生 > >React-native 完美解決 Unable to load script from assets “index.android.bundle” 和 JS server not recognize

React-native 完美解決 Unable to load script from assets “index.android.bundle” 和 JS server not recognize

前言:

React-Native的第一個HelloWorld工程,大多數人都能跑起來,可也有一部分人卡在第一個工程,就是難以跑出正確的介面,乾著急…

我這裡給出我遇到的坑,希望能夠幫助你,首先,給出我現在的開發環境版本:

版本宣告:

Node.js : v8.9.4

React-native: 0.53.3

Android studio 2.2.3(gradle自帶的版本是2.14.1)

如果你也是React-native 0.48以後的新版本,那麼恭喜你,我解決的問題可能就是你需要的

1.版本差異:

現在網上在給出接入環境報錯的大多數都是0.48以前的版本解決方案,0.48以前的版本根目錄下還有index.android.js和index.ios.js兩個js檔案,而在0.48以後就只有一個App.js這個檔案了

2.問題出現:

         可能大多數人第一次跑起工程時就會遇到下面的經典錯誤:

 

看到這裡大家各種百度,應該搜尋到的解決方案最多的是類似於下面這種:

但是,按照方法來並沒有卵用,因為它是0.48以前的版本解決方案,我們只需要新init一個專案,按照我的解決方法來,應該就能解決你的問題(不能解決的請給我留言)

3.分析問題:

其實0.48以後工程專案結構是完整的,不可能出現第一種錯誤index.android.bundle找不到的問題,所以真正的問題只能是後半句:make sure you are running a packager server

3.問題分析:

我們給張模擬的react-native執行的原理圖看一下:


如圖,我們可以看出問題可能出現在:

(1)	電腦react-native 伺服器根本沒起來,或者沒有被recognized識別到
(2)	手機配置的IP、埠與電腦伺服器的IP、埠不一致

4.問題解決

問題解決分為兩大步驟:

第一步,檢查JsServer是否正確開啟

判斷伺服器是否開啟,當我們執行 react-native run-android 命令時,分兩種情況:

(a)當前命令視窗提示startingjs service ,並自動彈出一個啟動service的視窗,提示js service成功run在 8081埠,那麼恭喜你,這一步你成功了,可以直接進行第二步 ;
(b)當前命令視窗不能自動彈出一個啟動service視窗,需要自己先執行react-natvie start 命令手動開啟一個服務視窗,再另啟動一個視窗執行react-native run-android命 令;
(i)如果提示JsService already started,那麼恭喜你,你也可以進入第二步了;
(ii)如果你的命令視窗提示黃色字型JS server not recognized , continuing with build


那麼,恭喜你,趕緊關掉視窗吧,你的js server 都沒有成功開啟,你可以提前終止任務了

JSserver not recognized解決:

         這種問題出現,說明你的8081埠被其他程式佔用了,你可以在命令列輸入netstat -aon|findstr "8081",你會發現一堆程式佔用8081埠,我的就是被java.exe程式頑固佔用,殺死又重啟佔用,沒辦法我只能react-native 伺服器換埠,解決方法如下:

(1)    新開一個視窗,例如執行react-native start --port 9043 --reset-cache 換一個沒有程式在用的埠(你可以執行netstat -aon|findstr "9043"看有沒有程式在用 這個埠 )
(2)    新開一個視窗,執行react-native run-android --port 9043
(3)    開啟手機或者模擬器的dev setting 設定IP埠,IP為計算機IP,埠為9043
(4)    再次執行react-native run-android --port 9043



第二步,檢查手機和電腦IP埠是否一致

         這裡除錯分為兩種情況:

(1)    run在真機上要保證電腦和手機處在同一區域網wifi中,手機能夠ping通電腦,並設定電腦的IP和埠,真機上就是搖晃手機,可以出現設定彈窗(注意手動開啟應用懸浮窗許可權),點選DEV setting ,選擇debug server host&port for device 選項,設定IP埠為電腦的IP埠(這裡的埠是前面說的JsService 開啟的埠,預設是 8081,如果你重設了Js Service 埠,例如9043,那麼你要改成ip:9043)
(2)    run在模擬器上,如果是原生模擬器,預設的IP是10.0.2.2這個不用改的,埠改成你Js Server對應的埠就行了,如果run在genymotion上,你可以設定成localhost:8081(你自己Js Server的埠) 

參考 : https://stackoverflow.com/questions/47341120/js-server-not-recognized-continuing-with-build




相關推薦

React-native 完美解決 Unable to load script from assetsindex.android.bundle JS server not recognize

前言: React-Native的第一個HelloWorld工程,大多數人都能跑起來,可也有一部分人卡在第一個工程,就是難以跑出正確的介面,乾著急… 我這裡給出我遇到的坑,希望能夠幫助你,首先,給出我現在的開發環境版本: 版本宣告: Node.js : v8.9.4 Re

win10 windows10 react-native rn 環境安裝配置Unable to load script from assets 'index.android.bundle終極解決方案

首先說明一下我的情況,新手開始學rn,之前只看過阮一峰大神和一個翻譯國外react入門的文章,然後直接開始rn配置,也是一步一步看著網上的教程開始的,剛開始問題太多,沒有寫中間的bug,直到最後這一個bug搞了我半個下午半個上午,今天上午終於看到期望已久的hello wor

Mac中真機測試React Native project時出現Unable to load script from assets 'index.android.bundle'

剛接觸學習React Native,在進行真機除錯時,報錯出現Unable to load script from assets ‘index.android.bundle’. Make sure your bundle is packaged correctl

react-native 啟動的時候報錯unable to load script from assets 'index.android bundle'

實行命令react-native run-android報以下錯誤 unable to load script from assets 'index.android bundle'  ,make su

React Native 學習之路:Unable to load script from assets 'index.android.bundle'.

 最近總遇到這個問題:問題背景:1.伺服器已啟動2.裝置插入了兩個裝置(模擬器與真機)3.之後出現以下報錯問題Unable to load script from assets 'index.android.bundle'. Make sure your bundle is

Unable to load script from assets 'index.android.bundle'.解決方案

剛接觸React Native,新建了一個專案,在Android Studio的模擬器上可以執行,但用Genymotion模擬器執行時卻報如下錯誤: 上網查了一下,很多文章都提出下面的解決方法: 1.首先手動在android/app/src/main目錄下建立一個as

unable to load script from assets 'index.android bundle' ,make sure your bundle is packaged correct

第一步:在 android/app/src/main 目錄下建立一個 assets空資料夾 第二步:執行 下面這段命令 react-native bundle –platform andr

unable to load script from assetsindex.android bundle’ ,make sure your bundle ...

unable to load script from assets ‘index.android bundle’ ,make sure your bundle is packaged correctly or youu’re runing a packager

react-native---配置reactnative報紅,run-Android時候報錯unable to load script from assets 'index.android.bundl

配置react-native環境時候報錯: unable to load script from assets 'index.android.bundle'.Make sure your bundle ispackged correctly or you

React Native for Android Nnable to load script from assets 'index.android bundle'

在android手機上執行react-native專案時 報錯:unable to load script from assets 'index.android bundle'  ,make sur

[React-Native] Unable to load script from assets 'index.android.bundle'.

unable als android win oid .com -i ets ava react native for android 拋出下面異常,解決方法: java.lang.RuntimeException: Unable to load script from

react-native 啟動的時候報錯unable to load script from assets 'index.android bundle'

實行命令react-native run-android報以下錯誤 unable to load script from assets 'index.android bundle'  ,make sure your bundle is packaged correctly or y

(轉)react-native unable to load script from assets

轉載自:https://blog.csdn.net/jasonzds/article/details/78747524問題:unable to load script from assets ‘index.android bundle’ ,make sure your bun

ReactNative--出現異常的解決方法:Unable to load script from assets 'index.android.bundle'

當我們搭建環境,執行第一個專案時手機介面出現紅色背景,這說明報異常了,不能正常編譯。我是在真機上進行的測試出現的問題。廢話不多說,上正題。 首先先說一個問題我這個是新版本建立的專案,此時專案根目錄是沒有index.android.js檔案的,我看網上說手動複製index.js重新命名一個

unable to load script from assets could not connect to development server解決方案

小編碰到該問題是在利用Android studio正確執行react native專案時遇見,可以正確編譯,但是不能顯示出正確介面,如下圖所示。解決方案:1.設定IP和埠報錯頁面晃動手機,顯示選單——點

Unable to load script from assets 'index.android.bundle' 出錯?

unable load spa 目錄 運行 roi win 程序 android 野路子太多,坑人真的!F**k 言歸正傳,當你運行 react native 程序的時候出現這個錯誤 ,如果您使用Windows,請按以下方式運行命令,或者如果出現錯誤“無法找到條目文件ind

Unable to load script from assets 'index.android.bundle'. Make sure your bundle is packaged correctl

第一種:使用bundle命令:(缺點:後續沒辦法reload,只能重複生成bundle檔案) 1.在Android/app/src/main目錄下建立一個空的assets資料夾 2: 在工程根目錄下資料bundle命令: react-native bundle --platform

項目初始化以後出現:Unable to load script from assets 'index.android.bundle

運行 rsquo users 新建 detail nts log ati use Mac中真機測試React Native project時出現Unable to load script from assets ‘index.android.bundle‘

unable to load script from assets-ReactNative新建專案採坑

1.開啟專案根目錄下的package.json        看下 版本號是不是0.56.0,是的話改成0.55.4; 2.劃重點 某個main資料夾下新建assets,你肯定知道是哪個main,做過好多次了就是沒用罷了。 react-native bun

react native unable to load script form assets 錯誤解決

注意:虛擬機器unable to load script form assets,可能是8081埠被佔用 真機除錯如果紅色錯誤錯誤 unable to load script form assets解決 1: android\app\src\main 下新建asse