简体   繁体   English

CRA 中的 setupProxy 文件使 react-scripts 启动失败,命令失败,退出代码 1 错误

[英]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.

相关问题 反应脚本启动错误代码 134,未启动应用程序 - react-scripts start error code-134, not starting application “react-scripts start”命令到底是什么? - What exactly is the 'react-scripts start' command? 在 CRA/react-scripts 中使用可选链接 (?.) - using optional chaining(?.) with CRA/react-scripts 新计算机上的“反应脚本启动”错误 - “react-scripts start” error on new machine 如何在没有反应脚本的情况下使用 -r @cypress/instrument-cra 进行代码覆盖 - How to use -r @cypress/instrument-cra for code coverage without react-scripts Npm start 给我:'react-scripts' 不是内部或外部命令,也不是可运行的程序或批处理文件。 - Npm start gives me : 'react-scripts' is not recognized as an internal or external command, operable program or batch file.' 无法启动 TypeScript ReactApp。 错误:未找到 react-scripts 命令 - Can't start TypeScript ReactApp. Error: react-scripts command not found npm start throws sh: react-scripts: command not found - npm start throws sh: react-scripts: command not found sh: react-scripts: 运行 npm start 后找不到命令 - sh: react-scripts: command not found after running npm start 命令“npm start”中的问题在第四个 tic-tac-toe@0.1.0 启动脚本中失败。 npm ERR:反应脚本:未找到 - Problem in the command "npm start" Failed at the fourth-tic-tac-toe@0.1.0 start script. npm ERR! react-scripts: not found
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM