DEV Community

Cover image for Developing and deploying create-react-app to multiple Firebase environments

Developing and deploying create-react-app to multiple Firebase environments

John Dean on September 12, 2019

Introduction create-react-app makes it easy to quickly get started with React. Firebase makes it easy to quickly get started with web de...
Collapse
 
rodiwa profile image
RD

I was running into issues when setting up proxy (in src/setupProxy.js). I went through the changelog for http-proxy-middleware and found that require/import of http-proxy-middleware is now explicit.

So please try const { createProxyMiddleware } = require('http-proxy-middleware'); instead of const proxy = require('http-proxy-middleware'); to fix this.

You basically need to do this now

const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
  app.use(
    '/__',
    createProxyMiddleware({
      target: 'http://localhost:4000'
    })
  );
};
Enter fullscreen mode Exit fullscreen mode

Hope this helps :)

Collapse
 
huanzhang89 profile image
Huan Zhang

Quick question regarding the http proxy. Why do we need that? The project seems to work fine locally without it.

Collapse
 
captemulation profile image
John Dean

The proxy will forward requests for firebase scripts to the firebase emulator. Without it, unless you load firebase some other way, firebase will not function

Collapse
 
jorgemasta profile image
Jorge Masta

Very helpful! 🙌
About typescript, it doesn't work for me.

I ended up using this workaround github.com/microsoft/TypeScript/is...