setupProxy.js not working together with TypeScript
See original GitHub issueIs 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 myapp
cd myapp
yarn add typescript @types/react @types/react-dom @types/jest
mv src/index.{js,tsx}
- 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/' }))
}
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”.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Custom Proxy in Create React App using Typescript
I got it working with vanilla javascript, but am unable to get it to work with TypeScript. Has anyone gotten setupProxy to work...
Read more >setupProxy.js does not work inside React App
Hello, I am having a setupProxy.js file under the src/ folder to deal with Cross-Origin Issues from localhost. However, it doesn't work and ......
Read more >Why you should use a proxy server with Create React App
Using a manually created proxy in Create React App json file, then create a new file named setupProxy. js in the src directory....
Read more >not working: http-proxy-middleware test - CodeSandbox
Activating extension 'vscode.typescript-language-features' failed: Could not find bundled tsserver.js.
Read more >Developing and deploying create-react-app to multiple ...
I was running into issues when setting up proxy (in src/setupProxy.js). I went through the changelog for http-proxy-middleware and found ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for the report!
You are right. For now, please add this line to your
tsconfig.json
:"exclude": ["src/setupProxy.js"]
Let me know if that fixes the issue for you.
@Timer it does not work in 2.1.1 for us. Workaround is working fine.