开发服务器在react native中返回response error code: 500

The development server returned response error code: 500 in react native

我正在使用 react-native 框架来开发我的 android 应用程序。我想使用 react-native-material-design 库来制作具有更多功能的 Toolbar

我在我的项目使用以下命令的当前目录中安装了这个库:-

E:\>npm i react-native-material-design -g --save
C:\Users\ch-e00925\AppData\Roaming\npm
`-- react-native-material-design@0.3.7
  +-- react-native-material-design-styles@0.2.6  (git+https://github.com/react-n
ative-material-design/react-native-material-design-styles.git#bdc029c1a1c83ff563
d10868be38b8aed1e9989b)
  `-- react-native-vector-icons@2.1.0
    +-- lodash@4.17.4
    `-- yargs@4.8.1
      +-- cliui@3.2.0
      | +-- strip-ansi@3.0.1
      | | `-- ansi-regex@2.1.1
      | `-- wrap-ansi@2.1.0
      +-- decamelize@1.2.0
      +-- get-caller-file@1.0.2
      +-- lodash.assign@4.2.0
      +-- os-locale@1.4.0
      | `-- lcid@1.0.0
      |   `-- invert-kv@1.0.0
      +-- read-pkg-up@1.0.1
      | +-- find-up@1.1.2
      | | +-- path-exists@2.1.0
      | | `-- pinkie-promise@2.0.1
      | |   `-- pinkie@2.0.4
      | `-- read-pkg@1.1.0
      |   +-- load-json-file@1.1.0
      |   | +-- graceful-fs@4.1.11
      |   | +-- parse-json@2.2.0
      |   | | `-- error-ex@1.3.0
      |   | |   `-- is-arrayish@0.2.1
      |   | +-- pify@2.3.0
      |   | `-- strip-bom@2.0.0
      |   |   `-- is-utf8@0.2.1
      |   +-- normalize-package-data@2.3.5
      |   | +-- hosted-git-info@2.1.5
      |   | +-- is-builtin-module@1.0.0
      |   | | `-- builtin-modules@1.1.1
      |   | +-- semver@5.3.0
      |   | `-- validate-npm-package-license@3.0.1
      |   |   +-- spdx-correct@1.0.2
      |   |   | `-- spdx-license-ids@1.2.2
      |   |   `-- spdx-expression-parse@1.0.4
      |   `-- path-type@1.1.0
      +-- require-directory@2.1.1
      +-- require-main-filename@1.0.1
      +-- set-blocking@2.0.0
      +-- string-width@1.0.2
      | +-- code-point-at@1.1.0
      | `-- is-fullwidth-code-point@1.0.0
      |   `-- number-is-nan@1.0.1
      +-- which-module@1.0.0
      +-- window-size@0.2.0
      +-- y18n@3.2.1
      `-- yargs-parser@2.4.1
        `-- camelcase@3.0.0


E:\>

此后我在 运行 应用程序时遇到一个问题,可能是库未成功安装。

E:\Myntra>react-native start
Scanning 557 folders for symlinks in E:\Myntra\node_modules (114ms)
 ┌────────────────────────────────────────────────────────────────────────────┐

 │  Running packager on port 8081.                                            │

 │                                                                            │

 │  Keep this packager running while developing on any JS projects. Feel      │

 │  free to close this tab and run your own packager instance if you          │

 │  prefer.                                                                   │

 │                                                                            │

 │  https://github.com/facebook/react-native                                  │

 │                                                                            │

 └────────────────────────────────────────────────────────────────────────────┘

Looking for JS files in
   E:\Myntra

[01/23/2017, 13:36:07] <START> Initializing Packager
[01/23/2017, 13:36:08]         HMR Server listening on /hot

React packager ready.

[01/23/2017, 13:36:12] <START> Requesting bundle
                               bundle_url: /index.android.bundle?platform=androi
d&dev=true&hot=true&minify=false
[01/23/2017, 13:36:40] <START> Building Haste Map
[01/23/2017, 13:36:40] <END>   Building Haste Map (141ms)
[01/23/2017, 13:36:40] <END>   Initializing Packager (33314ms)
[01/23/2017, 13:36:40] <START> Transforming files
transformed 584/607 (96%)(node:6316) UnhandledPromiseRejectionWarning: Unhandled
 promise rejection (rejection id: 605): UnableToResolveError: Unable to resolve
module react-native-material-design-styles from E:\Myntra\node_modules\react-nat
ive-material-design\lib\config.js: Module does not exist in the module map or in
 these directories:
  E:\Myntra\node_modules\react-native-material-design\node_modules
,   E:\Myntra\node_modules

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset packager cache: `rm -fr $TMPDIR/react-*` or `npm start -- --reset-cac
he`.
[01/23/2017, 13:54:09] <START> Requesting bundle
                               bundle_url: /index.android.bundle?platform=androi
d&dev=true&hot=true&minify=false

PS : 我在 Windows 7 机器上,找不到执行命令的方法。我看过这个 The development server returned response error code: 500 in react-native 但它对我没有帮助。

谁能帮我解决这个问题。提前致谢。

尝试在本地而不是全局安装 react-native-material-design

看起来 react-native-material-design 依赖于 react-native-material-design-styles,它不会被 React Native 的打包器打包,因为它的父级是一个全局模块。

如果您没有指定 .js 文件

的正确路径,有时会出现此错误

点赞而不是键入 正确的 路径:

var WeatherProject = require('./Main/WeatherProject');

A​​ 错误 路径输入(大小写、拼写错误、特殊符号):

var WeatherProject = require('./WeatherProject');

babel-preset-react-native惹这个麻烦。 运行 在您的项目根目录中执行以下命令:

$yarn remove babel-preset-react-native

$yarn add babel-preset-react-native@2.1.0

可能是您导入的 JavaScript 个文件的名称与 React 预定义的 libraries/components 相同。例如,从您创建的文件夹 app/components 导入 View.js。

import View from './app/components/View'

上面的语句会产生错误。因此,通过将文件名更改为 Interface.js

import Interface from './app/components/Interface'

现在,代码可以运行很好

出现此错误的原因之一是我导入了两次 'react-native' 库。

import { View, Text, ActivityIndicator } from "react-native";
import { View, Text, ActivityIndicator, TouchableOpacity, StyleSheet } from "react-native";

我不知道这是否真的会导致这个问题,但是删除多余的 import 行为我解决了这个问题。

先执行,获取版本号:

C:\WINDOWS\system32>react-native -v react-native-cli

2.0.1 react-native: 0.56.0

然后我卸载了react-native:

C:\WINDOWS\system32>npm uninstall -g react-native-cli

removed 41 packages in 3.999s

然后我安装了react-native:

npm install react-native@0.55.4

然后我安装了react-native-cli:

npm install -g react-native-cli@1.2.0

然后使用这个安装创建一个react-native项目:

react-native init --version="0.55.4" myprojectname

如果您使用的是 react-native 版本:56.0,则将其降级到 54 版本。它对我有用

我对端口 8081 有同样的问题,将其更改为 8082。因为它已经被其他一些服务使用,这对我来说是一步

First run your package server: Blockquote

react-native start --port 8082

Open another command prompt, start the Android app as usual:

react-native run-android

Once it finishes, now rewrite the tcp port that adb tunnels:

adb reverse tcp:8081 tcp:8082

See the list of adb tcp tunnels:

adb reverse --list

Now You should now see a message like:

(reverse) tcp:8081 tcp:8082

检查您的应用,它会 运行 ...............!

对于那些使用 stores 或顶级组件的人。如果您删除一个,请确保它没有被导入到其他任何地方。

就我而言,我删除了一个正在导入顶级的商店。

作为React-native领域的新人,我曾经无数次遇到过这种错误,而且总是一头雾水。不过,经过一些经验后,我意识到,当服务器试图从一个不存在的地方导入某些东西时,就会发生这种情况。

因此,检查您正在导入的所有内容以及该内容是否存在,必须是您应该开始的地方。

这意味着此错误不仅会针对已卸载的软件包弹出,即使您导入了错误的内容或从错误的位置导入也是如此。

react-native bundle --platform android --dev false --entry-file index.js --bundle-output android/app/src/main/assets/index.android.bundle --assets-dest android/app/src/main/res

运行 此命令:这将显示错误,例如两次关闭标签或无法找到任何模块

在基于 linux 的系统中的命令前使用 sudo

每当有人遇到这种错误代码为 500 的错误时。遵循这背后的原因。

1) 您可能在 Linux 系统中工作并且您必须 运行 使用终端应用程序并检查 Android 模拟器而不是在设备中。

2)如果您使用上述方法,请确保您的 Simulator Wife 应该关闭,然后使用 Studio 它将完美运行。

希望您能得到解决方案。

1) 您可能在 Linux 系统中工作并且您必须 运行 使用终端应用程序并检查 Android 模拟器而不是在设备中。

2) 如果您使用上述方法,请确保您的模拟器 Wifi 应该关闭,然后使用 Studio 它将完美运行。

3)确保不能同时打开多人终端或命令window。如果它然后关闭一个

  • 转到您的根项目
  • 打开 powershell
  • 运行 npm start —–reset-cache
  • 完成后,不要关闭它,同时在项目的根目录中打开另一个 powershell
  • 运行 react-native run-android

我遇到了同样的问题,我的一个节点模块配置不正确(反应导航)所以我只是使用

在本地重新安装它
npm install react-navigation --save

对于那些使用 stores 或顶级组件的人。如果您删除一个,请确保它没有被导入到其他任何地方。

就我而言,我删除了一个正在导入顶级的商店。

同样的错误。大小写不同。

当我在 Redux 文件夹中的 package.json 文件中将“名称”更改为小写时,我发生了这个错误。

我这样做是为了修复以下错误,这是由于 npm 约定只允许小写 { "message": "String does not match the pattern of \"^(?:@[a-z0-9-*~][a-z0-9-*._~]*/)?[a-z0-9-~][a-z0-9-._~]*$\".", }

所以为了解决这个问题我改变了 { "name": "Redux" }

{
    "name": "redux"
}

然后服务器错误就来了。我改回

{
    "name": "Redux"
}

然后它工作正常。

通常这个错误是因为指定了文件路径。

当我为图像的 require 函数提供错误的文件路径时出现此错误。

就我而言,就像

image: require('../assets/profile')

然后改成这个解决了我的错误,

image: require('./../assets/profile.jpg')

这个问题是由于“从节点模块中缺少一个模块”引起的,总是这个问题是由@babel模块解决方案引起的

$yarn remove babel-preset-react-native
$yarn add babel-preset-react-native@2.1.0

查看我的 github 上的问题:https://github.com/HAFDIAHMED/red_gear9/issues/1

我遇到了完全相同的问题,我尝试修复它,但在找到解决方案之前没有任何效果。 首先你需要检查你有什么版本的node js并降级它。 基本上你需要下载 NVM(节点版本管理器)。 然后按照此 link https://www.youtube.com/watch?v=RDScvojqAio

上的说明进行操作