'react-scripts start' command fails with node 18.0.0 if "proxy" entry is present in package.json
Describe the bug
When I try to start the development server with "npm run start", the 'react-scripts start' command fails, throwing this exception: `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.`
This happens only by switching to Node.js version 18.0.0, if in package.json the entry:
"proxy":"http://something" is present.
It doesn't show up if you delete that entry, and it doesn't show up with previous Node versions until 18.
Did you try recovering your dependencies?
$ yarn --version 1.22.18
Which terms did you search for in User Guide?
I searched for:
"react-script start fail" and for the error message:
"Invalid options object. Dev Server has been initialized using an options object that does not match the API schema."
Environment
Environment Info:
current version of create-react-app: 5.0.1
running from C:\Users\roralligator\AppData\Local\npm-cache\_npx\c67e74de0542c87c\node_modules\create-react-app
System:
OS: Windows 10 10.0.22000
CPU: (8) x64 Intel(R) Core(TM) i7-8550U CPU @ 1.80GHz
Binaries:
Node: 18.0.0 - C:\Program Files\nodejs\node.EXE
Yarn: 1.22.18 - C:\Program Files\nodejs\yarn.CMD
npm: 8.6.0 - C:\Program Files\nodejs\npm.CMD
Browsers:
Chrome: Not Found
Edge: Spartan (44.22000.120.0), Chromium (100.0.1185.44)
Internet Explorer: 11.0.22000.120
npmPackages:
react: ^18.0.0 => 18.0.0
react-dom: ^18.0.0 => 18.0.0
react-scripts: ^5.0.0 => 5.0.0
npmGlobalPackages:
create-react-app: Not Found
( It says Windows 10, but it's actually under Window 11 )
Steps to reproduce
- Install Node version 18.0.0
- Initialize a cra app with
yarn create react-appornpx create-react-app - Edit package.json adding : `"proxy":"http://localhost:5000"
- Start the app with
yarn startornpm run start
Expected behavior
The webpack development server should start within a few seconds.
Actual behavior
It throws an exception and exits:
$ react-scripts 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.
Reproducible demo
(Paste the link to an example project and exact instructions to reproduce the issue.)
@Kais3rP Just wanted to point out, i had this problem with node 16. Thanks for the question, your question included a workaround for me. :) For now i've gotten rid of the proxy and just hardcoded the backend's url for dev reasons and keep it in a separate changelist. This allows me to keep moving, and i appreciate you a ton for this question, again.