Skip to content

setupProxy.js not working together with TypeScript #5587

@rassie

Description

@rassie

Is this a bug report?

Yes

Environment

CRA ^2.0.6-next.c662dfb0 with TypeScript support

Steps to Reproduce

  1. npx create-react-app --scripts-version @next myapp
  2. cd myapp
  3. yarn add typescript @types/react @types/react-dom @types/jest
  4. mv src/index.{js,tsx}
  5. Add src/setupProxy.js with following content:
const proxy = require('http-proxy-middleware')
    
module.exports = function(app) {
    app.use(proxy('/api', { target: 'http://localhost:5000/' }))
}
  1. yarn run build

Expected Behavior

setupProxy.js should be compiled without any problems.

Actual Behavior

Behold the "Type error: Cannot compile namespaces when the '--isolatedModules' flag is provided. TS1208" error message.

Additionally: if one were to rewrite the setupProxy.js script with proper ES6 exports like this:

const proxy = require('http-proxy-middleware')
    
export const setupProxy = (app) => {
    app.use(proxy('/api', { target: 'http://localhost:5000/' }))
}

yarn run build compiles successfully, while yarn run start claims "unexpected token export".

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions