Skip to content
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

setupProxy.js doesn't support Flow #5185

Closed
holloway opened this issue Oct 1, 2018 · 5 comments
Closed

setupProxy.js doesn't support Flow #5185

holloway opened this issue Oct 1, 2018 · 5 comments

Comments

@holloway
Copy link
Contributor

holloway commented Oct 1, 2018

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.
@Timer
Copy link
Contributor

Timer commented Oct 1, 2018

This is the expected behavior. This file runs in the Node environment and as such, only supports its syntax.

@Timer Timer added this to the 2.0.0 milestone Oct 1, 2018
@Timer
Copy link
Contributor

Timer commented Oct 1, 2018

df98c0c

@Timer Timer closed this as completed Oct 1, 2018
@RodneyU215
Copy link

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.

@Timer
Copy link
Contributor

Timer commented Oct 22, 2018

@RodneyU215 that proxy seems pretty simple, does the normal proxy string option not work for your use case?
Don't mind me if it was a reduced case.

@RodneyU215
Copy link

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

@lock lock bot locked and limited conversation to collaborators Jan 9, 2019
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

3 participants