To resolve the error "Invalid options object. Dev Server has been initialized using an options object that does not match the API schema," follow these steps:
- Check Dev Server Configuration: Review the configuration settings for your development server to ensure that they adhere to the correct schema.
- Update Dev Server Options: If you've recently updated your development server or made changes to its configuration, ensure that the options object provided during initialization matches the current API schema.
- Validate Configuration Settings: Double-check the configuration settings you're passing to the development server initialization function.
- Consult Documentation or Community: If you're unsure about the correct configuration settings or how to resolve the error, consult the official documentation for your development server or reach out to the community for assistance.
- Check for Updates or Patches: Sometimes, this error can occur due to bugs or inconsistencies in the development server software. Check for any available updates or patches that may address compatibility issues or schema mismatches.
- Debugging and Testing: Use debugging techniques to identify which specific option or configuration setting is causing the error.
- Revert Changes: If you recently made changes to your development server configuration and started encountering this error, consider reverting those changes to a known working state.
Here is a workaround:
Delete the line "proxy": "http://localhost:6000"
from your configuration.
Then, install the package http-proxy-middleware
using the command npm install http-proxy-middleware --save
.
Create a file named setupProxy.js
inside your src
folder or at the root of your project directory.
Add the following lines inside setupProxy.js
:
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:6000',
changeOrigin: true,
})
);
}
The other solutions didn't work for me, so here's what I found:
This seems to be a Create React App (CRA) bug or possibly a security feature, where allowedHosts
gets set to [undefined]
because prepareUrls
doesn't set lanUrlForConfig
when both a host and a proxy are specified. You can find the relevant CRA GitHub issue here.
If appropriate for your use case (learn more here), this issue can be avoided by creating a .env
file and adding DANGEROUSLY_DISABLE_HOST_CHECK=true
to it, or by trying DANGEROUSLY_DISABLE_HOST_CHECK=true yarn start
.
Setting "allowedHosts"
as a property in package.json
didn't work for me. I had to wrap it in an options
property:
"options": {
"allowedHosts": ["localhost", ".localhost"],
"proxy": "https://localhost:3386/"
}
After that, running npm start
did the trick without having to reinstall modules.
If you add or remove "proxy": "http://localhost:6000"
in package.json
, then remove node_modules
and reinstall it. This works for me.
I faced the same issue several times, but finally, I found a solution!
I solved this problem by adding "allowedHosts": "all"
to my package.json
file.
Example:
"allowedHosts": "all",
"proxy": "http://localhost:3001/api",
"name": "simple-blog",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^5.1"
}
Read Similar Articles
- Sample image upload rest api for testing
- Create Stored Procedure with Output and Input parameters in SQL
- After Update Trigger in Sql Server With Example
- Difference between View and Indexed View or Materialized
- [Answer]-"unable to find a target named `runnertests` in project `runner.xcodeproj`, did find `runner`."
- SignalR authentication with Bearer Token Step By Step
- [Answer]-redux , webpack-cli: Invalid options object. Dev Server has been initialized using an options object
- Reading CSV File with cells containing commas c#