美文网首页
react proxy is not a function

react proxy is not a function

作者: MAYDAY77 | 来源:发表于2020-12-10 15:39 被阅读0次

拉下来react项目后执行了npm i之后npm start启动项目报错如下:

proxy is not a function,启动失败。

在配置代理时,按照官方给出的代理配置

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

module.exports = function(app){

  app.use(proxy('/api', { target: 'http://localhost:5000/' }));

};

检查package.json发现,   

"http-proxy-middleware": "^1.0.6",

http-proxy-middleware   1.x版本做了比较大的更改,

正确的写法如下:

const {createProxyMiddleware} = require('http-proxy-middleware');

module.exports = function(app){

  app.use(createProxyMiddleware('/api', { target: 'http://localhost:5000/' }));

};

再次启动项目就不报错了。ok啦。

最后看看阿信和邓紫棋

相关文章

网友评论

      本文标题:react proxy is not a function

      本文链接:https://www.haomeiwen.com/subject/fwcrgktx.html