[英]setupProxy file in CRA makes react-scripts start fail with Command failed with exit code 1 error
I've added the following setupProxy file according to the example in the docs :我根据文档中的示例添加了以下 setupProxy 文件:
const proxy = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/address',
proxy({
target: 'https://zip-cloud.appspot.com/api',
changeOrigin: true,
})
);
};
But whenever I want to start the npm start command it fails with the following error: error Command failed with exit code 1.
但是每当我想启动 npm start 命令时,它都会失败并显示以下错误:
error Command failed with exit code 1.
I have no clue why it's not working.我不知道为什么它不起作用。 I'm using the newest CRA version and I'm using typescript.
我正在使用最新的 CRA 版本,并且正在使用打字稿。 Any help would be appriciated!
任何帮助都会受到赞赏!
Try:尝试:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/address',
createProxyMiddleware({
target: 'https://zip-cloud.appspot.com/api',
changeOrigin: true,
})
);
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.