-
Notifications
You must be signed in to change notification settings - Fork 10.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WebpackError: package.json does not exist at /package.json when building with Firebase SDK #3686
Comments
Yeah, the problem is your code is trying to run code that calls node.js APIs e.g. I haven't used Firebase much but I'm guessing you're requiring the wrong module. There should be one that's designed for using in frontend code. |
@KyleAMathews No, the Firebase client JS SDK is made for use in the browser, and I have used it in other projects (including next.js projects) where this is not an issue. |
I ended up switching back to create-react-app for now, with the same code and dependencies and the webpack bundling is working fine. I would be interested to eventually switch back to Gatsby if I can get some help making it work with Firebase. |
It could just be that we're still on webpack v1 until Gatsby v2 is released. |
I am trying to solve this problem as Firestore and Gatsby are going to give me the best results for my use case. I've been looking at this for a few days now and keep landing on the idea that the NPM modules for Firebase (and/or Firestore) are not the same as the modules Google specifies in their Web examples. (https://firebase.google.com/docs/firestore/quickstart?authuser=0) They direct you to include script tags that point to a set of bundles. And some have found that the objects coming from both NPM and these bundles are different. See: firebase/firebase-js-sdk#464 (electron and vue, but really the same problem and workaround) Also I would like to suggest that since firestore works flawlessly for development using webpack dev server, is there some tweaking we can do to how Gatsby 1.9 uses the current version of webpack for prod builds? I am not familiar with how Gatsby uses webpack (only how you can override with modifyWebpackConfig). But if I could be pointed in the right direction, i'd be happy to investigate the differences between dev and prod builds to see why one works and one does not. I still have yet to try adding the scripts via tags for https://www.gstatic.com/firebasejs/4.9.0/firebase.js and https://www.gstatic.com/firebasejs/4.9.0/firebase-firestore.js but only if there is a way it can co-exist in my development environment that really requires es6 modules. Let me know if anyone has any thoughts on this information. Thanks. |
@willcode4food have you seen the docs page on modifying the webpack config? It describes the different build stages and links to the source of Gatsby's webpack config. Note that Gatsby v2 will be upgrading from webpack version one to version three or four, so the specifics of the webpack setup may change significantly. |
Think this has to do something with grpc/grpc#11435 |
Found this as well firebase/firebase-js-sdk#221 |
Hey FYI, upgrading to Gatsby v2.0.0-alpha.8 solved these issues. I am pleased to say that you will be able to use Google Firestore upon the release of 2.0.0 |
I still get this error, i use firebase |
If you are still using gatsby v1 for whatever reason, delete your |
Hey @deegha I have been struggling with this issue for the last few days. Have you found a solution for Next.js? |
No couldn't get it done, so i wrote a google cloud function to query the firebase database and called an https request from the client side (next,js app) using node-fetch to the cloud functions. so technically i wrote an api using google cloud functions. that was my solution. |
Thank you! but this didn't work but i used "firebase": "^5.9.2". should i use "firebase 4.x" or using firebase 5 would do ? |
@deegha I had to use 4.x to get firebase working with gatsby v1 |
@deegha I FOUND A WORK AROUND. Holy hell, that was about 2 weeks of errors. Okay, I'm a little bit excited so I'll try to explain the best I can. The issue comes from a problem with gRPC (a dependency of firebase/firestore), which has trouble finding bindings from node-pre-gyp (it's dependency) on Windows. So instead of importing Firebase like this:
With this work around, you can cache these scripts to your user's browser. However, this will result in increased loading times ONLY for the first time your user enters your website. Other than that, the website should actually run just as fast (maybe even faster). You don't even need to bother creating an external API (unless that's what you'd like to do). To access your database, you can do a simple firebase.firestore()...get() but make sure your user has Firebase installed in their cache before you try something like this or you will get an error stating that firebase.firestore() is not a function. Let me know if you have any questions :) |
Thank you very much for the update. anyway i have created that API so i decided to go with that. |
on Next.js this link fixed it for me : https://lifesaver.codes/answer/fail-to-deploy-with-firebase-as-a-dependency even my next version is 9.3.4 |
I'm seeing this build error in my project after starting to use the Firebase SDK when building (develop works fine), in the static HTML build phase:
I spent 2 days searching for answers related to webpack errors with gRPC and node-pre-gyp, came across grpc/grpc#13049 and webpack/webpack#1599 and tried their solutions by adding the following to my gatsby-node.js:
But all with no luck. If anyone has any clue, that would be great because right now I'm unable to deploy to production. I even tried a fresh install of Node and NPM to make sure there was no environment issue.
Environment
Gatsby version: 1.9.166
Node.js version: 8.9.4
Operating System: Mac OS
File contents:
gatsby-config.js
:pathPrefix: '/admin'
package.json
:Steps to reproduce
The text was updated successfully, but these errors were encountered: