【发布时间】:2022-01-19 05:57:13
【问题描述】:
当我添加 "proxy": "http://localhost:6000" 时,我一直在关注我的项目中的这个错误
在我的 package.json 中。
这是纱线启动后的错误响应。
无效的选项对象。开发服务器已使用 与 API 架构不匹配的选项对象。
- options.allowedHosts[0] 应该是一个非空字符串。 error 命令失败,退出代码为 1。 info 访问 https://yarnpkg.com/en/docs/cli/run 获取相关文档 命令。
但是当我删除 "proxy": "http://localhost:6000" 时一切都很好。
这是在我的 package.json 中:
{
"name": "client",
"version": "0.1.0",
"private": true,
"dependencies": {
"@material-ui/core": "^4.12.3",
"@testing-library/jest-dom": "^5.16.1",
"@testing-library/react": "^12.1.2",
"@testing-library/user-event": "^13.5.0",
"axios": "^0.24.0",
"moment": "^2.29.1",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-file-base64": "^1.0.3",
"react-redux": "^7.2.6",
"react-scripts": "5.0.0",
"redux": "^4.1.2",
"redux-thunk": "^2.4.1",
"web-vitals": "^2.1.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": [
"react-app",
"react-app/jest"
]
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
},
"proxy": "http://localhost:6000"
}
【问题讨论】:
-
如果你删除它一切都很好,为什么不删除它?
-
因为可能需要它?我需要它将我的 api 请求代理到我的反应应用程序中的后端。但是,是的,我也在寻找解决方案
-
这篇githubmemory.com/repo/facebook/create-react-app/issues/11762的文章有原因但还没有解决办法
标签: node.js reactjs package.json