question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setupProxy.js doesn't support Flow

See original GitHub issue

Is this a bug report?

Yes.

Did you try recovering your dependencies?

Yes.

Which terms did you search for in User Guide?

“proxy” and “setupProxy”

Steps to Reproduce

  1. make a src/setupProxy.js with Flow annotations (the “: *”) like,

     // @flow
     const proxy = require('http-proxy-middleware');
     module.exports = function(app: *) {
       app.use(proxy('/api', { target: 'http://localhost:3001/' }));
     };
    
  2. run yarn start

Expected Behavior

The usual dev server startup

Actual Behavior

    $ yarn start
    yarn run v1.7.0
    $ react-scripts start
    Unexpected token :
    error Command failed with exit code 1.
    info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
RodneyU215commented, Oct 23, 2018

Hi @Timer! Yes the normal proxy string does work for this use case. I was merely highlighting the incompatibility with es2015 module syntax.

1reaction
RodneyU215commented, Oct 22, 2018

I stumbled upon this issue #5185 because I was experiencing the exact same “Actual Behavior”. What fixed things for me was changing my setupProxy.js file from this:

# setupProxy.js

import proxy from 'http-proxy-middleware';

export default function(app) {
  app.use(proxy('/api', { target: 'http://localhost:5000/' }));
};

to this:

# setupProxy.js

const proxy = require('http-proxy-middleware');

module.exports = function(app) {
  app.use(proxy('/api', { target: 'http://localhost:5000/' }));
};

I’m commenting incase it saves someone else time in the future.

Read more comments on GitHub >

github_iconTop Results From Across the Web

node.js - setupProxy is not working - http-proxy-middleware
The problem is not the setupProxy.js, the problem is that the path to which axios is posting does not exist in the backend....
Read more >
setupProxy.js does not work inside React App
Hello, I am having a setupProxy.js file under the src/ folder to deal with Cross-Origin Issues from localhost. However, it doesn't work and ......
Read more >
Proxying API Requests in Development - Create React App
The proxy option supports HTTP, HTTPS and WebSocket connections. ... Next, create src/setupProxy.js and place the following contents in it:.
Read more >
ASP.NET 6 + React APIs - Microsoft Q&A
I describe the process in my environment below hoping this will help. (1) The proxy settings are included in the setupProxy.js file:.
Read more >
Proxy does not work with the React build version - JavaScript
Proxy works with 'npm start' but does not work with the React build version ... @nhcarrigan Can you please help with this? ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found