Skip to content

when I yarn start the project will show me “proxy is not a function” #8550

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
tanweiweiweiweiwei opened this issue Feb 24, 2020 · 8 comments

Comments

@tanweiweiweiweiwei
Copy link

tanweiweiweiweiwei commented Feb 24, 2020

src/setupProxy.js
const proxy = require('http-proxy-middleware')

module.exports = function(app) {
app.use(proxy('/api',
{
target: "",
changeOrigin:true,
pathRewrite: {
"^/api": "/"
}
}))
}

@tanweiweiweiweiwei tanweiweiweiweiwei changed the title when I yarn when I yarn start the project will show me “proxy is not a function” Feb 24, 2020
@will-shaw
Copy link

@tanweiweiweiweiwei

I had the same issue, with version 1.0.0 of http-proxy-middleware you'll need to use

const { createProxyMiddleware } = require('http-proxy-middleware');

There's already a PR to update the documentation.
#8541

@adeedchoudhury
Copy link

Thanks @will-shaw I have a similar issue but am still getting the same error when I use

const { createProxyMiddleware } = require('http-proxy-middleware');

Any ideas on what could still be causing the issue?

@tanweiweiweiweiwei
Copy link
Author

@tanweiweiweiweiwei

I had the same issue, with version 1.0.0 of http-proxy-middleware you'll need to use

const { createProxyMiddleware } = require('http-proxy-middleware');

There's already a PR to update the documentation.
#8541

Thank you so much

@will-shaw
Copy link

will-shaw commented Feb 25, 2020

@adeedchoudhury Short of checking that you have v1.0.0 of http-proxy-middleware and you've done an npm install the only other thing I could suggest might be double checking you also renamed the function call.

module.exports = function(app) {
  app.use(
    '/api',
-     proxy({	    
+    createProxyMiddleware({
      target: 'http://localhost:5000',
      changeOrigin: true,
    })
}

@adeedchoudhury
Copy link

@will-shaw thanks! I forgot about renaming the function call.

@GautamUpreti123
Copy link

@will-shaw still facing the same error: proxy is not a function. Could you please help.

I have done all the above-said things:

const { proxy } = require('http-proxy-middleware');
module.exports = function (app) {
app.use('/api',
proxy({
target: 'http://localhost:3000',
changeOrigin: true
}))
}

@meneseswill
Copy link

meneseswill commented Mar 1, 2020

@GautamUpreti123, use this:

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(
    '/api',
    createProxyMiddleware({
      target: 'http://localhost:3000',
      changeOrigin: true
    })
  );
};

@ianschmitz
Copy link
Contributor

Closing as we have a PR up to update the documentation.

@lock lock bot locked and limited conversation to collaborators Mar 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants