【问题标题】:The development server returned response error code: 500 in react native开发服务器返回响应错误代码:500 in react native
【发布时间】:2017-06-07 18:00:28
【问题描述】:

我正在使用react-native 框架来开发我的安卓应用程序。我想使用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
  • @EmilioRodriguez 是的,它起作用了 谢谢我想知道如果我在全球范围内安装 npm 包会有什么不同的原因?您能否回答这个问题,以便我可以将其标记为已接受答案

标签: android react-native react-native-android


【解决方案1】:

babel-preset-react-native 麻烦你了。在您的项目根目录中运行以下命令:

$yarn remove babel-preset-react-native

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

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • 他在做:npm i react-native-material-design -g --save 而他应该在做:npm i react-native-material-design --save
    • 我试过了,但错误没有解决
    【解决方案3】:

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

    首先运行你的包服务器: 块引用

    react-native start --port 8082
    

    打开另一个命令提示符,像往常一样启动 Android 应用:

    react-native run-android
    

    一旦完成,现在重写 adb 隧道的 tcp 端口:

    adb reverse tcp:8081 tcp:8082
    

    查看 adb tcp 隧道列表:

    adb reverse --list
    

    现在您应该会看到如下消息:

    (reverse) tcp:8081 tcp:8082
    

    检查您的应用它将运行......!

    【讨论】:

    • 我已经尝试了上述所有步骤,但对我不起作用
    【解决方案4】:

    有时会出现此错误当您没有指定正确的路径 .js 文件

    喜欢而不是键入正确路径:

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

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

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

    【讨论】:

    • 谢谢 确实这是个问题。我把我的文件名大写了,忘记在导入声明中更改它
    • 感谢您在输入错误图像路径时得到您的回答。
    • 谢谢,我浏览了我所有的文件,并意识到我仍然有一个使用我最近删除的以前文件的导入语句。
    • 这正是问题所在
    【解决方案5】:
    • 转到您的根项目
    • 打开powershell
    • 运行npm start —–reset-cache
    • 完成后,不要关闭它并同时在项目的根目录中打开另一个 powershell
    • 运行react-native run-android

    【讨论】:

    • 我已按照上述步骤操作,但对我不起作用
    • 这对我有用
    【解决方案6】:

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

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

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

    【讨论】:

    • 我已经尝试过这个解决方案,但它没有帮助我
    【解决方案7】:

    首先执行,获取版本号:

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

    2.0.1 反应原生:0.56.0

    然后我卸载了 react-native:

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

    在 3.999 秒内删除了 41 个包

    然后我安装了 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
    

    【讨论】:

    • 这个解决方案没有帮助我修复错误
    【解决方案8】:

    我遇到了同样的问题,我的一个节点模块没有配置好(反应导航),所以我只是在本地重新安装它

    npm install react-navigation --save
    

    【讨论】:

    • 尝试此操作后没有帮助我遇到同样的问题
    【解决方案9】:

    作为 React-native 领域的新手,我曾经多次面对这种错误,并且总是感到困惑。不过,经过一些经验,我意识到,当服务器尝试从不存在的地方导入某些东西时,就会发生这种情况。

    因此,检查您正在导入的所有内容,如果该内容存在,则必须从您应该开始的地方开始。

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

    【讨论】:

      【解决方案10】:

      每当有人遇到这种错误代码为 500 的错误时。以下原因。

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

      2)如果您使用上述方法,请确保您的 Simulator Wife 已关闭,然后与 Studio 一起使用它会完美运行。

      希望你能得到解决方案。

      【讨论】:

        【解决方案11】:

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

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

        3) 确保不要同时打开多伙伴终端或命令窗口。如果它关闭一个

        【讨论】:

          【解决方案12】:

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

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

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

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

          现在,代码可以正常运行了

          【讨论】:

            【解决方案13】:

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

            【讨论】:

              【解决方案14】:

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

              在我的例子中,我删除了一个正在顶级导入的商店。

              【讨论】:

                【解决方案15】:

                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

                【讨论】:

                  【解决方案16】:

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

                  在我的例子中,我删除了一个正在顶级导入的商店。

                  【讨论】:

                    【解决方案17】:

                    同样的错误。不同的情况。

                    当我将 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"
                    }
                    

                    然后它就可以正常工作了。

                    【讨论】:

                      【解决方案18】:

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

                      当我给 image 的 require 函数提供了错误的文件路径时,我得到了这个错误。

                      在我的情况下,就像

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

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

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

                      【讨论】:

                        【解决方案19】:

                        问题是由“缺少节点模块中的模块”引起的,问题总是由@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

                        【讨论】:

                          【解决方案20】:

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

                          【讨论】:

                            猜你喜欢
                            • 2017-04-09
                            • 2021-09-16
                            • 1970-01-01
                            • 2020-04-29
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            相关资源
                            最近更新 更多