create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

'react-scripts start' command fails with node 18.0.0 if "proxy" entry is present in package.json

Open Kais3rP opened this issue 3 years ago • 1 comments

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

  1. Install Node version 18.0.0
  2. Initialize a cra app with yarn create react-app or npx create-react-app
  3. Edit package.json adding : `"proxy":"http://localhost:5000"
  4. Start the app with yarn start or npm 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 avatar Apr 22 '22 06:04 Kais3rP

@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.

OleDakotaJoe avatar Dec 07 '23 19:12 OleDakotaJoe