create-react-app: Invalid options object. Dev Server has been initialized using an options object that does not match the API schema.
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:)
- Install http-proxy-middleware
- 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,
})
);
};
- 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.
About this issue
- Original URL
- State: open
- Created 2 years ago
- Reactions: 6
- Comments: 29
Commits related to this issue
- Add proxy workaround due to https://github.com/facebook/create-react-app/issues/12304 — committed to yuvadm/geshem.space by yuvadm 2 years ago
- Fix proxy config Closes #1300 Apply fix from https://github.com/facebook/create-react-app/issues/12304#issuecomment-1486249284 setupProxy.js was already present — committed to uellue/LiberTEM by uellue a year ago
- Fix proxy config Closes #1300 Apply fix from https://github.com/facebook/create-react-app/issues/12304#issuecomment-1486249284 setupProxy.js was already present — committed to LiberTEM/LiberTEM by uellue a year ago
Workaround: set env
DANGEROUSLY_DISABLE_HOST_CHECK=true
Getting this issue without configuring
http-proxy-middleware
.To reproduce:
npx create-react-app some-app
some-app/package.json
to add"proxy": "http://localhost:4000"
HOST=something.local npm run start
You shall see the following logged in your terminal.
Configuration
same error, I don’t know why, but it works . after eject, open file : webpackDevServer.config.js change allowedHosts: disableFirewall ? ‘all’ : [allowedHost], to allowedHosts: disableFirewall ? ‘all’ : “localhost”
is it still not fixed? I am using react 18.2.0 and react-dom 18.2.0 with this line in my package.json “proxy”: “http://localhost:3000” and i am getting the same error as op. It is very strange because a day before it was working and now i am getting this error also with new react projects. Changing the versions of react does not help. Only changing the lines like in the commit of Manc is working for me.
Edit: Okay found out it only appers when connected to internet with public ip instead of a private nat ip.
The issue seems to be occurring when you put
in the
package.json
file.Configuring the proxy middleware manually works fine https://create-react-app.dev/docs/proxying-api-requests-in-development/#configuring-the-proxy-manually
Doesn’t work.
I stumbled on the same error when updating to node 18.0.0, it works normally with node 17.0.0. #12316
Allow cors on the server side to tick this problem. I was using a chrome extension CORS to bypass it.
I am getting the same behaviour. For me it was working on all my commits yesterday but today it fails with this error on the exact same commits.
git status
is clean on all the commits.The workaround mentioned works for me
Thanks @rexpan
i just reproduced this one. Steps to reproduce: 1 , npx create-react-app my-app1 2 , cd my-app1 3 , just add “proxy”: “http://localhost:3008/” into package.json 4 , npm run dev , or npm start
environment is win10 , nodejs 16.15.1