Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • C create-react-app
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 1,547
    • Issues 1,547
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 417
    • Merge requests 417
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • Meta
  • create-react-app
  • Issues
  • #5587
Closed
Open
Issue created Oct 26, 2018 by Administrator@rootContributor

setupProxy.js not working together with TypeScript

Created by: 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".

Assignee
Assign to
Time tracking