无效的选项对象。开发人员服务器已使用与API架构不匹配的选项对象进行初始化 [英] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema
本文介绍了无效的选项对象。开发人员服务器已使用与API架构不匹配的选项对象进行初始化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
"proxy": "http://localhost:6000"
时,我在我的项目中记录了此错误
在我的Package.json中。
这是纱线开始后的错误响应。
选项对象无效。开发人员服务器已使用 与API架构不匹配的Options对象。
- options.alloweHosts[0]应为非空字符串。错误命令失败,退出代码为%1。信息访问 https://yarnpkg.com/en/docs/cli/run以获取有关此问题的文档 命令。
但当我移除"proxy": "http://localhost:6000"
时,一切正常。
这在我的包上。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"
}
推荐答案
以下是解决办法。删除代理:http://localhost:6000";.(&Q)使用命令安装包http-Proxy-Middlewarenpm安装http-Proxy-Middleware--保存。在src文件夹中创建一个setupProxy.js文件。在内部添加以下行:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:6000',
changeOrigin: true,
})
);
};
现在,运行您的应用程序。它应该可以工作。
这篇关于无效的选项对象。开发人员服务器已使用与API架构不匹配的选项对象进行初始化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文