gatsby-packages icon indicating copy to clipboard operation
gatsby-packages copied to clipboard

This is a browser-targeted Firebase bundle... error on gatsby build

Open Andrewjeska opened this issue 5 years ago • 15 comments


[                            ]   0.001 s 0/5 0% Building static HTML for pages
[2020-06-19T01:28:49.445Z]  @firebase/app:
      Warning: This is a browser-targeted Firebase bundle but it appears it is being
      run in a Node environment.  If running in a Node environment, make sure you
      are using the bundle specified by the "main" field in package.json.
      If you are using Webpack, you can specify "main" as the first item in
      "resolve.mainFields":
      https://webpack.js.org/configuration/resolve/#resolvemainfields

      If using Rollup, use the rollup-plugin-node-resolve plugin and specify "main"
      as the first item in "mainFields", e.g. ['main', 'module'].
      https://github.com/rollup/rollup-plugin-node-resolve

All I want to use is firebase/auth. I have this imported in gatsby-browser.js and gatsby-ssr.js as per the docs. Is there something here that I need to do to get it to work? Let me know what other details would be helpful!

Andrewjeska avatar Jun 19 '20 01:06 Andrewjeska

Im seeing this too

molebox avatar Jun 20 '20 19:06 molebox

Hey @Andrewjeska, @molebox, can you try removing the import "firebase/auth" from gatsby-ssr.js?

You don't need the Firebase import lines in gatsby-ssr.js.

alexluong avatar Jun 20 '20 20:06 alexluong

@alexluong I'm seeing the same issue. Everything works with npm run develop issue is only when running npm run build

Priyatham51 avatar Jun 22 '20 05:06 Priyatham51

I've seen moved off gatsby for separate reasons, but I do remember trying it without the import in gatsby-ssr.js

I think it has to do with how it's used within your components.

Andrewjeska avatar Jun 22 '20 17:06 Andrewjeska

I'm seeing this with npm run develop too, tried removing the import from gatsby-ssr.js but nothing changed. Using version 0.2.0-beta.4.

ps-feng avatar Jun 23 '20 15:06 ps-feng

This is the fix: https://gist.github.com/jeffreymeng/78bd7f6b0f301fa5ef04359cd512222b

molebox avatar Jun 24 '20 15:06 molebox

I just need to use import "firebase/database" and I'm seeing this message too, what can I do?

alfredohzb avatar Jul 01 '20 02:07 alfredohzb

Running into this issue as well, if there isn't a current fix it would be great to see the documentation updated to warn about this problem as it's pretty frustrating to have gotten so far into development to find that following the documentation leads to errors in usage.

gristleism avatar Jul 23 '20 15:07 gristleism

I have replicated this issue on a project I'm working on. You can find the repo here. Most of the firebase stuff is in src/firebase/firebaseService.tsx

It works fine when running gatsby develop but gatsby build produces the following error. Screen Shot 2020-08-13 at 1 14 20 PM

Marcusg62 avatar Aug 13 '20 19:08 Marcusg62

Can you try removing these lines and move them inside the function scope?

const googleProvider = new firebase.auth.GoogleAuthProvider()
const facebookProvider = new firebase.auth.FacebookAuthProvider()

const auth = firebase.auth()
const db = firebase.firestore()
const firebaseFunctions = firebase.functions()

alexluong avatar Aug 13 '20 19:08 alexluong

I'm assuming this is what you mean.

https://github.com/Marcusg62/inhouse-marketing-site/blob/7df3aa47a2e58454db5bc3623f04a408d562a089/inhouse-marketing/src/firebase/firebaseService.tsx#L97-L103

Done. I get the same error when trying to build. I've pushed to master if you'd like to take a look. Screen Shot 2020-08-13 at 1 25 56 PM

Marcusg62 avatar Aug 13 '20 19:08 Marcusg62

@alexluong I recommend archiving this repo.

Marcusg62 avatar Aug 25 '20 04:08 Marcusg62

Any luck on a solution for this?

theskillwithin avatar Oct 15 '20 01:10 theskillwithin

This is the fix: https://gist.github.com/jeffreymeng/78bd7f6b0f301fa5ef04359cd512222b

This patch worked for me (react-firebase-hooks + gatsby-plugin-firebase using for auth only)

fczuardi avatar Mar 10 '21 06:03 fczuardi

Hey all, just wanted to post an update to this thread in case anyone else is trying to get Firebase working in production.

I highly recommend you check out how the gatsby-firebase-simple-auth starter handles this issue. Shout out to Marco Melilli for building this starter.

He uses client-only routes for the login page and protected routes with the Gatsby Plugin Create Client Path

In any case, the solution is simple to follow and was quick to integrate.

suntudo avatar Jul 16 '21 15:07 suntudo