SetupProxy file not being read in Create React App Typescript

Viewed 1060

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?

1 Answers

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

"exclude": ["src/setupProxy.js"]
Related