Skip to content

setupProxy.js doesn't support Flow #5185

Closed

Description

@holloway

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.

Activity

  1. Timer commented on Oct 1, 2018

    @Timer
    Contributor

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

  2. added this to the 2.0.0 milestone on Oct 1, 2018
  3. Timer commented on Oct 1, 2018

    @Timer
    Contributor
  4. RodneyU215 commented on Oct 22, 2018

    @RodneyU215

    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.

  5. Timer commented on Oct 22, 2018

    @Timer
    Contributor

    @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.

  6. RodneyU215 commented on Oct 23, 2018

    @RodneyU215

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

  7. locked and limited conversation to collaborators on Jan 9, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions