JS服务器未被识别,继续构建。
JS服务器未被识别,继续构建。
环境
Windows 10
Npm 5.5.1
react-native-cli 2.0.1
react-native 0.50.3
Genymotion Google Nexus 7 - 6.0.0 API 23
Android相关:
Sdk版本:26
buildToolsVersion '26.0.2'
Targetsdk版本:26
compile "com.android.support:appcompat-v7:26.0.2"
我已经运行了npm start --reset-cache和react-native start --reset-cache命令,但仍然无法识别JS服务器,继续构建。这会阻止打包器在模拟器上运行之前绑定资源。
我按照这个帖子上的解决方案1进行了操作:
https://github.com/facebook/react-native/issues/9136#issuecomment-306486102
以及这个:
我使用react-native init APP命令开始了这个项目。但是在构建过程中遇到了这个错误。我在这里和其他网站上查看了一些帖子,提到了使用npm cache clean和react-native start --reset-cache命令,但似乎没有什么帮助,我仍然遇到同样的错误。曾经有一段时间我顺利运行它,但是我修改了一个npm包,我想我又搞砸了。非常感谢任何帮助。我还更新了gradle版本并将其同步到项目中。
以下是我遇到的一些截图...
** 代码 **
index.js
import { AppRegistry } from 'react-native'; import App from './App'; AppRegistry.registerComponent('hihi', () => App);
App.js
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react'; import { Platform, StyleSheet, Text, View } from 'react-native'; const instructions = Platform.select({ ios: 'Press Cmd+R to reload,\n' + 'Cmd+D or shake for dev menu', android: 'Double tap R on your keyboard to reload,\n' + 'Shake or press menu button for dev menu', }); export default class App extends Component<{}> { render() { return (); } } const styles = StyleSheet.create({ container: { flex: 1, justifyContent: 'center', alignItems: 'center', backgroundColor: '#F5FCFF', }, welcome: { fontSize: 20, textAlign: 'center', margin: 10, }, instructions: { textAlign: 'center', color: '#333333', marginBottom: 5, }, }); Welcome to React Native! To get started, edit App.js {instructions}
app.json
{
"name": "hihi",
"displayName": "hihi"
}
.babelrc
{
"presets": ["react-native"]
}
package.json
{ "name": "hihi", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.0.0", "react-native": "0.50.3", "watchman": "^0.1.8" }, "devDependencies": { "babel-jest": "21.2.0", "babel-polyfill": "^6.26.0", "babel-preset-es2015": "^6.24.1", "babel-preset-react-native": "4.0.0", "babel-register": "^6.26.0", "jest": "21.2.1", "react-test-renderer": "16.0.0" }, "jest": { "preset": "react-native" } }
更新 更新
我找到了解决方法,这是参考了这个帖子和这个解决方案的结合:
Could not find com.android.tools.build:gradle:3.0.0-alpha1 in circle ci
我需要在两个地方都包含google(),同时还需要将端口号切换为8082,并在模拟器上启用该端口。非常感谢大家的帮助!!! =)
问题出现的原因是JS server无法被识别,导致构建过程中出现了"JS server not recognized, continuing with build"的错误信息。解决这个问题的方法是更改端口,并且还需要从设备本身进行端口的更改。
首先,确认是否是这个问题:
$> netstat -aon|findstr “8081”
然后,将端口更改为新的默认端口:
a)在Windows上更改环境变量以设置RN的新端口:
$> SET RCT_METRO_PORT=8083
这在RN中用作默认端口,如果未设置,则默认为8081
b)删除旧的反向端口:
$> adb reverse –remove-all
c)为adb设备设置新的反向端口:
$> adb reverse tcp:8083 tcp:8083
d)将设备上的Dev设置从默认的8081更改为8083。
运行应用程序,然后运行input keyevent 82,
现在选择Dev Settings > Debug Server host … > 输入新的url:localhost:8083
重新构建和运行。
在使用React Native时,我遇到了一个问题,错误提示为“JS server not recognized, continuing with build”。经过查找,我找到了出现这个问题的原因,并且找到了解决方法。
这个问题出现的原因是因为我在使用端口8081时,另外一个进程正在运行。
解决这个问题的步骤如下:
- 使用命令
lsof -i tcp:8081
查找正在使用端口8081的进程 - 获取进程的PID,以我为例是
25120
- 使用命令
kill -9 25120
杀死该进程 - 重新启动React Native
按照上述步骤,我成功解决了“JS server not recognized, continuing with build”的问题。这个问题的解决方法非常简单,只需要找到并关闭占用8081端口的进程,然后重新启动React Native即可。
在这篇文章中,我们将讨论一个关于JS服务器无法识别的问题以及解决方法。在这个问题中,用户在构建过程中遇到了一个错误信息(JS server not recognized, continuing with build)。下面是一些用户在类似情况下采取的步骤:
1. 在不同于8081端口的端口上运行packager:react-native start --port 8082 --reset-cache
2. 在第二个命令提示符窗口中运行命令:react-native run-android --port 8082
3. 当错误屏幕出现时,按下Ctrl + M
4. 点击底部的Dev Settings
按钮
5. 点击Debug server host & port for device
按钮
6. 输入localhost:8082
并点击OK
按钮
7. 再次运行命令:react-native run-android --port 8082
通过执行这些步骤,用户至少成功连接到了服务器。然而,他们再次遇到了以下错误:Loading dependency graph, done. Bundling index.js [development, non-minified] 0.0% (0/1), failed. error: bundling failed: NotFoundError: Cannot find entry file index.js in any of the roots: ["c:\'starter_application_name"] at DependencyGraph._getAbsolutePath (MY_COMPUTER\node_modules\metro-bundler\src\node-haste\DependencyGraph.js:305:11) at DependencyGraph.getDependencies
。
这个错误提示说它找不到index.js文件,并且不知道原因。尝试了以上步骤后,用户建议尝试运行react-native start --port 8082 --reset-cache
命令。在第2和第7步中,命令应改为react-native run-android --port 8082
。
用户还提到他们是否使用Git-Bash而不是CMD提示符可能与问题有关。他们尝试了添加PATH变量,并且还尝试将它们添加到bashrc文件中。然而,在之前并没有遇到此问题,所以他们尝试了所有可用的方法。
在讨论中,其他用户提到可能是因为默认端口8081已被其他进程占用。另一个用户提到他们卡在了"warning: the transform cache was reset. Loading dependency graph, done."的问题上,并询问下一步应该做什么。
最后,有人问应该在哪里输入ctrl + M
。
以上就是关于(JS server not recognized, continuing with build)这个问题的原因和解决方法的整理。希望这些步骤能帮助到遇到类似问题的人。