CRA 5.0.0加入代理后项目启动报错

问题描述:
https://github.com/facebook/create-react-app/issues/11762#issue-1080972271
即:
在package.json中设置proxy, 然后通过npm start或yarn start启动项目, 报错如下:

>yarn start
yarn run v1.22.10
$ react-scripts start
Attempting to bind to HOST environment variable: test.localhost
If this was unintentional, check that you haven't mistakenly set it in your shell.
Learn more here: https://cra.link/advanced-config

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
 - options.allowedHosts[0] should be a non-empty string.
error Command failed with exit code 1.

解决方法: 不要在package.json中设置proxy, 而是在src/setupProxy.js中设置, 同时要将package.json中的proxy删掉,最后重新npm start即可.

你可能感兴趣的:(react,react.js,前端,json)