English 中文(简体)
无效备选办法反对。 “Dev服务器”已采用与APICSchema不匹配的备选物体进行初步化。
原标题:Invalid options object. Dev Server has been initialized using an options object that does not match the API schema

I have been stuck on this error in my project when I add "proxy": "http://localhost:6000" in my package.json.

This is the error response after yarn start.

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. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

But everything is fine when I remove the "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"
}
最佳回答

这里是一场工作。 删除proxy”:“http:// localhost:6000”。 www.un.org/Depts/DGACM/index_chinese.htm 在您的剪辑或文件夹根内创建文件setupProxy.js。 在以下部分添加这些内容:

const { createProxyMiddleware } = require( http-proxy-middleware );

module.exports = function(app) {
  app.use(
     /api ,
    createProxyMiddleware({
      target:  http://localhost:6000 ,
      changeOrigin: true,
    })
  );
};

Now, run your app. It should work.

问题回答

其它解决办法对我来说并不可行。

这似乎是一种CRA bug(安全特征?)? 登上<代码>[未定义]是因为<代码>prepareUrls 无论在东道国还是代理人,都注明了<条码>。 The relevant CRA/2006/5 issue is here

学习更多”,可以通过创建>recode>、releases_

快速解决办法是down web Pack edition using reactscripts

在<代码> 包装.json中,您的反应堆应用文档作了改动。

<<>Replace>/strong>

"react-scripts": "5.*", 

"react-scripts": "4.0.3",

Remove node_modules, 并再次为你的反应堆安装成套设备。

Run npm audit fix --force And while still connected to the internet Run npm start

工作报酬

删除<代码> 包装-锁.json_node_modules的夹,然后运行npm i 这个问题已经解决。

Reverting back to an older version of node worked for me. First of all clear npm s cache and install older version of node.

    > sudo npm cache clean -f
    > sudo npm install -g n
    > sudo n <version>

Latest version 18 is not work for me;version 14.8.2 work for me as I was used this edition. 您可以尝试以下任何版本:

I just debugged the issue in JS Debugger.

Node v18 changed os.networkInterfaces() family:

v18.0.0
The family property now returns a number instead of a string.

This is throwing off address module used by react-scripts which checks family against "IPv4"

我以“网上-中风”解决方案作为其他办法解决了这一问题。 但是,为了适当开展工作,我不得不关闭我的大门。 Saeed Kolivand 上文的答复=

因此,我的团队也存在同样的问题,即“条形”的错误。 我们下面概述的解决办法是一个非常具体的错误,很可能与许多人无关。

就我们而言,allowedHosts[0] 变量未作界定,我们发现allowedHosts[0]node_modules eact-scriptsconfigweb PackDevServer.config.js 上的变量。

module.exports = function (proxy, allowedHost) {
  const disableFirewall =
    !proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK ===  true ;
  return {
    // WebpackDevServer 2.4.3 introduced a security fix that prevents remote
    // websites from potentially accessing local content through DNS rebinding:
    // https://github.com/webpack/webpack-dev-server/issues/887
    // https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
    // However, it made several existing use cases such as development in cloud
    // environment or subdomains in development significantly more complicated:
    // https://github.com/facebook/create-react-app/issues/2271
    // https://github.com/facebook/create-react-app/issues/2233
    // While we re investigating better solutions, for now we will take a
    // compromise. Since our WDS configuration only serves files in the `public`
    // folder we won t consider accessing them a vulnerability. However, if you
    // use the `proxy` feature, it gets more dangerous because it can expose
    // remote code execution vulnerabilities in backends like Django and Rails.
    // So we will disable the host check normally, but enable it if you have
    // specified the `proxy` setting. Finally, we let you override it if you
    // really know what you re doing with a special environment variable.
    // Note: ["localhost", ".localhost"] will support subdomains - but we might
    // want to allow setting the allowedHosts manually for more complex setups
    allowedHosts: disableFirewall ?  all  : [allowedHost],

<代码>urls.lanUrlForConfig>通过到汇簿上:node_modules eact-scriptsstart.jsallowedHost

const createDevServerConfig = require( ../config/webpackDevServer.config );
...
createDevServerConfig(proxyConfig, urls.lanUrlForConfig)

<代码>urls.lanUrlForCofig由prepareUrl<>/code>功能载于node_modules eact-dev-utilsWeb PackDevServerUtils.js

const urls = prepareUrls(
  protocol,
  HOST,
  port,
  paths.publicUrlOrPath.slice(0, -1)
);

In the prepareUrls function, urls.lanUrlForConfig is set as undefined in the case that the computer s IPv4 address is non-private as seen below:

try {
  // This can only return an IPv4 address
  lanUrlForConfig = address.ip();
  if (lanUrlForConfig) {
    // Check if the address is a private ip
    // https://en.wikipedia.org/wiki/Private_network#Private_IPv4_address_spaces
    if (
      /^10[.]|^172[.](1[6-9]|2[0-9]|3[0-1])[.]|^192[.]168[.]/.test(
        lanUrlForConfig
      )
    ) {
      // Address is private, format it for later use
      lanUrlForTerminal = prettyPrintUrl(lanUrlForConfig);
    } else {
      // Address is not private, so we will discard it
      lanUrlForConfig = undefined;
    }
  }
} catch (_e) {
  // ignored
}

So in the end, we determined that the reason why we were having the error was because the ip address that we being pulled from the machine was non-private due to some ethernet cable configurations (We were getting a 169. address, an APIPA one, that was because the machine couldn t reach a DHCP server). This caused the urls.lanUrlForConfig to be undefined, which would ultimately get passed all the way down to the allowedHosts[0] variable and cause the error.

由于无法与DHCP服务器连接,这是另一个问题,但作为发展目的的热点,我们把“DANGEROUSLY_DISABLE_HOST_CHECK=true添入了我们的<代码>。 在我们的一揽子计划中设置“所有<>/代码”。 json是另一个解决办法。

为了克服这一问题,你在管理<条码>npm 开始时,刚刚必须与互联网连接。

这一错误是第18.0版的,我用第16.15.0版尝试进行罚款。

我只是在把第18.0.0号改为第15.00号时才发现这一错误。 查阅proxy: 固定了这一系统,但这不是我的选择,我想避免服务器上的代理中联网。 如果您转而采用先前的Node版本,即17.0.0,那就行了罚款。 我认为,在独立审查委员会小组不处理这个问题之前,这可以成为更好的选择。

5.0.1 反应稿没有复制,但差错在5.0时发生。 我猜想你可以用5.0.1解决这一问题。

If you add or remove "proxy": "http://localhost:6000" in package.json, then remove node_modules and reinstall it. This works for me.

面对同样的问题,但最后我找到了解决办法!

我通过在我的一揽子计划中增加“所有”<<>>>>>>>。 json文件

例:

"allowedHosts": "all",
"proxy": "http://localhost:3001/api",
"name": "simple-blog",
"version": "0.1.0",
"private": true,
"dependencies": {
  "@testing-library/jest-dom": "^5.1

另一种解决办法是,在您的.env档案中添加“,以便解决问题。

如果你使用网上包装,则会有所不同。

const { createProxyMiddleware } = require( http-proxy-middleware ); 
module.exports = {
plugins: [
    new createProxyMiddleware({
        target:  http://localhost:6000 ,
        changeOrigin: true,
      })
],
}

i) 面临同样的问题,但没有任何其他守则或结构操纵,我首先产生了新的反应。 我刚刚安装了所有附属设施,这些附属设施见于未投入使用者的 j子档案,我删除了 no锁单元。 json file from the response-app which is not work. 我删除了json案的所有内容,并复制了所有东西,从新的反应性app子案卷到旧的json案卷,并在救了我在码头安装了Npm,并投入了工作。





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签