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
npx create-react-app --scripts-version @next myappcd myappyarn add typescript @types/react @types/react-dom @types/jestmv src/index.{js,tsx}- Add
src/setupProxy.jswith following content:
const proxy = require('http-proxy-middleware')
module.exports = function(app) {
app.use(proxy('/api', { target: 'http://localhost:5000/' }))
}
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".