react项目中,package.json中proxy的配置如下

 "proxy": {
"/api/rjwl": {
"target": "http://47.94.142.215:8081",
"changeOrigin": true
}
}

就会报这样的错误

When specified, "proxy" in package.json must be a string.
Instead, the type of "proxy" was "object".
Either remove "proxy" from package.json, or make it a string.

原因:

原来React新版本不支持那样设置反向代理了

解决方案

安装 http-proxy-middleware

$ npm install http-proxy-middleware --save
$ # or
$ yarn add http-proxy-middleware

然后

在创建一个setupProxy.js文件,在src目录,src/setupProxy.js

const proxy = require('http-proxy-middleware')

module.exports = function (app) {
app.use(proxy('/rjwl', {
target: 'http://47.94.142.215:8081',
secure: false,
changeOrigin: true,
pathRewrite: {
"^/rjwl": "/rjwl"
}
}))
}

如果请求站点为https

则需要加上这个"changeOrigin":true

否则则会报错

参考地址:

https://www.blyoo.com/4007.html

项目

https://github.com/besswang/rj_cash_admin

react proxy 报错的更多相关文章

  1. 【问题与解决】Mac OS通过 npm 安装 React Native 报错(checkPermissions Missing write access to /usr/local/lib/node_modules)

    报错情况: 当Mac OS通过 npm 安装 React Native 报错,警告文字为:checkPermissions Missing write access to /usr/local/lib ...

  2. webStrom中React语法提示,React语法报错处理

    1,webStrom中React语法报错 ①, 取消Power Save Mode的勾选 File——Power Save Mode ②,webstorm开发react-native智能提示 随便在一 ...

  3. react+typescript报错集锦<持续更新>

    typescript报错集锦 错误:Import sources within a group must be alphabetized.tslint(ordered-imports) 原因:impo ...

  4. 使用Visual Studio Code调试React Native报错

    报错信息: [Error] Error: Unknown error: not all success patterns were matched. It means that "react ...

  5. react native报错处理com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process

    背景:最近准备在使用react-native开发的app中接入友盟,来进行用户行为统计,分享,授权登录等操作. 在使用的过程中,遇到了一些错误信息,在此记录一下. 在修改android目录下的buil ...

  6. react编译报错:Import in body of module; reorder to top import/first

    原因是这样的: 我把一个组件分为三个文件, |—Home.jsx // 业务逻辑与html Home——|—Home.css // 样式 |—index.js // 引入Home.css ,再把Hom ...

  7. React篇-报错信息:warning: Can't call setState (or forceUpdate) on an unmounted component.

    报错信息是: Warning: Can't call setState (or forceUpdate) on an unmounted component. This is a no-op, but ...

  8. react native 报错日常 if (_total > 0) { ~~~~~~ ^ ~ 1 error generated.

    node_modules/react-native/React/Base/RCTJavaScriptLoader.mm::: error: ordered comparison between poi ...

  9. React表格报错Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.

    解决: <Table bordered rowKey={record=>record.id} //解决 components={this.components} columns={colu ...

随机推荐

  1. JAVA中使用LOG4J记录日志(转)

    在项目开发中,记录错误日志是一个很有必要功能.一是方便调试:二是便于发现系统运行过程中的错误:三是存储业务数据,便于后期分析: 在java中,记录日志,有很多种方式. 比如,自己实现. 自己写类,将日 ...

  2. 利用referer属性,记录百度搜索跳转参数

    从百度搜索结果跳转到指定链接前,百度会发送一些参数,可以利用referer属性,在本站访问时记录百度跳转来之前的一些参数. 利用百度跳转前参数,进行一些相关的seo优化. 目前所用到的一些参数说明如下 ...

  3. OpenCV3 for python3 学习笔记1

    1.读/写图像文件 OpenCV的imread()函数和imwrite()函数能支持各种静态图像文件格式.不同系统支持的文件格式不一样,但都支持BMP格式,通常还应该支持PNG.JPEG和TIFF格式 ...

  4. java-算法-排列组合

    package com.qinghuainvest.utils.algorithm; import java.util.ArrayList; import java.util.Arrays; impo ...

  5. 使用scp命令在多个Linux系统间进行文件复制

    一,什么是scp scp是linux系统下基于ssh登陆进行安全的远程文件拷贝命令.scp命令可以在linux服务器之间复制文件和目录.scp使用ssh安全协议传输数据,具有和ssh一样的验证机制,从 ...

  6. centos7下使用mysql离线安装包安装mysql5.7

    服务器环境: centos7 x64 需要安装mysql5.7+ 一.卸载CentOS7系统自带mariadb # 查看系统自带的Mariadb [root@CDH-141 ~]# rpm -qa|g ...

  7. [android警告]AndroidManifest.xml警告 Not targeting the latest versions of Android

    警告:Not targeting the latest versions of Android; compatibility modes apply.Consider testing and upda ...

  8. JSONObject、JSONArray、Map、JavaBean的相互转换

    1,JSONObject json对象,就是一个键对应一个值,使用的是大括号{ },如:{key:value} 2,JSONArray json数组,使用中括号[ ],只不过数组里面的项也是json键 ...

  9. Java中Lambda表达式的使用(转)

    https://www.cnblogs.com/franson-2016/p/5593080.html 简介(译者注:虽然看着很先进,其实Lambda表达式的本质只是一个"语法糖" ...

  10. VMware下centOS yum报错cannot find a valid baseurl or repo:base 解决方法

    *无法联网的明显表现会有: 1.yum install出现 Error: cannot find a valid baseurl or repo:base 2.ping host会提示unknown ...