I am working on a react project and am running into some issues with http-proxy-middleware. I followed the readme and my setupProxy.js file looks like this
const {createProxyMiddleware} = require('http-proxy-middleware'); module.exports = function(app) { app.use( '/api', createProxyMiddleware({ target: 'https://localhost:3000', changeOrigin: true }) ); };
Anyone have any ideas as to why this might be occurring? From what I've seen, this is the correct way to set this up. Any response or suggestions will be greatly appreciated.
Removing the brackets works for me
const createProxyMiddleware = require('http-proxy-middleware');
Found that fix here https://www.reddit.com/r/reactjs/comments/jzoo3y/createproxymiddleware_is_not_a_function_how_can_i/
If all React js component files are in the component folder(or in another folder) then shift your Setupproxy.js file in that folder now you can use
const { createProxyMiddleware } = require('http-proxy-middleware');
For global, put your Setupproxy.js file in src folder then you have to remove {}
const createProxyMiddleware = require('http-proxy-middleware');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With