Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SetupProxy file not being read in Create React App Typescript

I have this code using CRA --template typescript in setupProxy.js file

const { createProxyMiddleware } = require('http-proxy-middleware');

module.exports = function (app) {
  app.use(
    '/user/try',
    createProxyMiddleware({
      target: 'http://localhost:8002',
      changeOrigin: true,
    })
  );
};

but the problem is that setupProxy.js file is completely ignored causing my request to fail.

I know I can use the "proxy": "http://localhost:8002" in package.json but it will not accept multiple proxies.

To further test, I also created a new CRA but without typescript and suddenly it's working with the same code above.

Is there a way to make setupProxy.js work in CRA typescript?

like image 983
ajbee Avatar asked Feb 25 '20 04:02

ajbee


People also ask

Can we use TypeScript in Create react app?

New App From Scratch If you're building a new app and using create-react-app , the docs are great: You can start a new TypeScript app using templates. To use our provided TypeScript template, append --template typescript to the creation command.


1 Answers

Should be able to just add this to your tsconfig.json. Hope it works for you.

"exclude": ["src/setupProxy.js"]
like image 141
Luke Glasscock Avatar answered Oct 01 '22 09:10

Luke Glasscock