question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.

See original GitHub issue

Describe the bug

I’m trying to access the Apis in my local server throug the react app and I got this issue:

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.

Did you try recovering your dependencies?

8.3.1

Which terms did you search for in User Guide?

proxy in local environment

Environment

 System:
    OS: Windows 10 10.0.19044
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Node: 16.14.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 8.3.1 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.1266.0), Chromium (100.0.1185.44)
    Internet Explorer: 11.0.19041.1566
  npmPackages:
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    react-scripts: 5.0.0 => 5.0.0
  npmGlobalPackages:
    create-react-app: Not Found

Steps to reproduce

(Write your steps here:)

  1. Install http-proxy-middleware
  2. Create setupProxy and add this code:
const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/',
    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
  );
};
  1. npm start

Expected behavior

The app should be started normally.

Actual behavior

I got this error:

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.

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:15

github_iconTop GitHub Comments

29reactions
rexpancommented, May 7, 2022

Workaround: set env DANGEROUSLY_DISABLE_HOST_CHECK=true

6reactions
detjcommented, May 29, 2022

Getting this issue without configuring http-proxy-middleware.

To reproduce:

  1. Run npx create-react-app some-app
  2. Edit some-app/package.json to add "proxy": "http://localhost:4000"
  3. Run HOST=something.local npm run start

You shall see the following logged in your terminal.

> some-app@0.1.0 start
> react-scripts start

Attempting to bind to HOST environment variable: something.local
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.

Configuration

node@16.15.0
npm@8.5.5
create-react-app@5.0.1
react-scripts@5.0.1
Read more comments on GitHub >

github_iconTop Results From Across the Web

Invalid options object. Dev Server has been initialized using ...
Here is a workaround. Delete "proxy": "http://localhost:6000". Install package http-proxy-middleware with command npm install ...
Read more >
Invalid options object. Dev Server has been initialized using ...
To solve the error Invalid options object. Dev Server has been initialized using an options object that does not match the API schema,...
Read more >
Dev Server has been initialized using an options object that ...
This is the error response after yarn start. Invalid options object. Dev Server has been initialized using an options object that does not...
Read more >
invalid options object. dev server has been initialized - You.com
webpack.config.js [webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
Read more >
Setting up the Webpack Dev Server - Three.js Tutorials
[webpack-cli] Invalid options object. Dev Server has been initialized using an options object that does not match the API schema. - options has...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found