WebpackError: FirebaseError: Firebase: Error (auth/invalid-api-key)

Good morning.

I have this gatsby site. It built smoothly… but now, for some reason I couldn’t figure out, it won’t build. It can’t/shouldn’t be the environment because it already built with it, although one error message states that…

I also found here that it might have been github changing name files, but it didn’t occur.

Here is the repo

  • netlify site name: site
    or site

  • error message: WebpackError: FirebaseError: Firebase: Error (auth/invalid-api-key)

  • Build problems:

2:40:09 PM: Build ready to start
2:40:11 PM: build-image version: 73def8bb10593b9b818f44989a75ea508018ccb7 (focal)
2:40:11 PM: build-image tag: v4.5.2
2:40:11 PM: buildbot version: 007e3cee9690c5dd1ea3d0f59b0390ab3a4afae2
2:40:11 PM: Building without cache
2:40:11 PM: Starting to prepare the repo for build
2:40:11 PM: No cached dependencies found. Cloning fresh repo
2:40:11 PM: git clone https://github.com/jcgsr/jan-MeusEscritos
2:40:12 PM: Preparing Git Reference refs/heads/main
2:40:12 PM: Parsing package.json dependencies
2:40:13 PM: Starting build script
2:40:13 PM: Installing dependencies
2:40:13 PM: Python version set to 2.7
2:40:14 PM: Downloading and installing node v16.13.2...
2:40:14 PM: Downloading https://nodejs.org/dist/v16.13.2/node-v16.13.2-linux-x64.tar.xz...
2:40:15 PM: Computing checksum with sha256sum
2:40:15 PM: Checksums matched!
2:40:18 PM: Now using node v16.13.2 (npm v8.1.2)
2:40:18 PM: Started restoring cached build plugins
2:40:18 PM: Finished restoring cached build plugins
2:40:18 PM: Attempting ruby version 2.7.2, read from environment
2:40:20 PM: Using ruby version 2.7.2
2:40:20 PM: Using PHP version 8.0
2:40:20 PM: Started restoring cached node modules
2:40:20 PM: Finished restoring cached node modules
2:40:21 PM: Installing NPM modules using NPM version 8.1.2
2:40:35 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
2:40:35 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
2:40:36 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
2:40:36 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
2:40:36 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
2:40:36 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
2:40:38 PM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
2:40:46 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
2:40:46 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
2:40:47 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
2:40:48 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
2:40:52 PM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
2:40:53 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
2:41:05 PM: npm WARN deprecated core-js@2.6.12: core-js@<3.4 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
2:41:19 PM: added 1862 packages, and audited 1863 packages in 58s
2:41:19 PM: 213 packages are looking for funding
2:41:19 PM:   run `npm fund` for details
2:41:20 PM: 35 vulnerabilities (11 moderate, 22 high, 2 critical)
2:41:20 PM: To address issues that do not require attention, run:
2:41:20 PM:   npm audit fix
2:41:20 PM: To address all issues (including breaking changes), run:
2:41:20 PM:   npm audit fix --force
2:41:20 PM: Run `npm audit` for details.
2:41:20 PM: NPM modules installed
2:41:20 PM: Started restoring cached go cache
2:41:20 PM: Finished restoring cached go cache
2:41:20 PM: go version go1.16.5 linux/amd64
2:41:20 PM: go version go1.16.5 linux/amd64
2:41:20 PM: Installing missing commands
2:41:20 PM: Verify run directory
2:41:22 PM: ​
2:41:22 PM: ────────────────────────────────────────────────────────────────
2:41:22 PM:   Netlify Build                                                 
2:41:22 PM: ────────────────────────────────────────────────────────────────
2:41:22 PM: ​
2:41:22 PM: ❯ Version
2:41:22 PM:   @netlify/build 26.1.3
2:41:22 PM: ​
2:41:22 PM: ❯ Flags
2:41:22 PM:   baseRelDir: true
2:41:22 PM:   buildId: 61e1b5795cfb0647e75f89c1
2:41:22 PM:   deployId: 61e1b5795cfb0647e75f89c3
2:41:22 PM: ​
2:41:22 PM: ❯ Current directory
2:41:22 PM:   /opt/build/repo
2:41:22 PM: ​
2:41:22 PM: ❯ Config file
2:41:22 PM:   No config file was defined: using default values.
2:41:22 PM: ​
2:41:22 PM: ❯ Context
2:41:22 PM:   production
2:41:22 PM: ​
2:41:22 PM: ❯ Installing plugins
2:41:22 PM:    - @netlify/plugin-gatsby@1.0.3
2:41:28 PM: ​
2:41:28 PM: ❯ Loading plugins
2:41:28 PM:    - @netlify/plugin-gatsby@1.0.3 from Netlify app
2:41:29 PM: ​
2:41:29 PM: ────────────────────────────────────────────────────────────────
2:41:29 PM:   1. @netlify/plugin-gatsby (onPreBuild event)                  
2:41:29 PM: ────────────────────────────────────────────────────────────────
2:41:29 PM: ​
2:41:30 PM: No Gatsby cache found. Building fresh.
2:41:30 PM: Add `gatsby-plugin-netlify` to `gatsby-config.js` if you would like to support Gatsby redirects. 🎉
2:41:30 PM: ​
2:41:30 PM: (@netlify/plugin-gatsby onPreBuild completed in 15ms)
2:41:30 PM: ​
2:41:30 PM: ────────────────────────────────────────────────────────────────
2:41:30 PM:   2. Build command from Netlify app                             
2:41:30 PM: ────────────────────────────────────────────────────────────────
2:41:30 PM: ​
2:41:30 PM: $ npm run build
2:41:30 PM: > gatsby-starter-default@0.1.0 build
2:41:30 PM: > gatsby build
2:41:33 PM: success open and validate gatsby-configs, load plugins - 0.660s
2:41:33 PM: info Loaded gatsby-plugin-firebase-v9.0
2:41:33 PM: success onPreInit - 0.006s
2:41:34 PM: success initialize cache - 0.291s
2:41:34 PM: success copy gatsby files - 0.096s
2:41:34 PM: success Compiling Gatsby Functions - 0.368s
2:41:34 PM: success onPreBootstrap - 0.379s
2:41:34 PM: success createSchemaCustomization - 0.006s
2:41:35 PM: success Checking for changed pages - 0.001s
2:41:35 PM: success source and transform nodes - 0.415s
2:41:35 PM: info Writing GraphQL type definitions to /opt/build/repo/.cache/schema.gql
2:41:36 PM: success building schema - 1.840s
2:41:36 PM: success createPages - 0.000s
2:41:37 PM: success createPagesStatefully - 0.357s
2:41:37 PM: info Total nodes: 47, SitePage nodes: 7 (use --verbose for breakdown)
2:41:37 PM: success Checking for changed pages - 0.000s
2:41:37 PM: success onPreExtractQueries - 0.000s
2:41:43 PM: success extract queries from components - 6.126s
2:41:43 PM: success write out redirect data - 0.055s
2:41:43 PM: warning The icon(src/images/gatsby-icon.png) you provided to 'gatsby-plugin-manifest' is not square.
2:41:43 PM: The icons we generate will be square and for the best results we recommend you provide a square icon.
2:41:43 PM: success Build manifest and related icons - 0.477s
2:41:43 PM: success onPostBootstrap - 0.519s
2:41:43 PM: info bootstrap finished - 13.462s
2:41:44 PM: success write out requires - 0.082s
2:43:05 PM: warning DefinePlugin
2:43:05 PM: Conflicting values for 'process.env'
2:43:05 PM: success Building production JavaScript and CSS bundles - 81.131s
2:43:34 PM: success Building HTML renderer - 29.079s
2:43:34 PM: success Execute page configs - 0.031s
2:43:34 PM: success Caching Webpack compilations - 0.001s
2:43:34 PM: success run queries in workers - 0.106s - 9/9 84.84/s
2:43:34 PM: success Running gatsby-plugin-sharp.IMAGE_PROCESSING jobs - 111.947s - 8/8 0.07/s
2:43:34 PM: success Merge worker state - 0.002s
2:43:34 PM: success Rewriting compilation hashes - 0.001s
2:43:34 PM: success Writing page-data.json files to public directory - 0.005s - 7/7 1450.21/s
2:43:43 PM: error Page data from page-data.json for the failed page "/edit/": {
2:43:43 PM:   "componentChunkName": "component---src-pages-edit-js",
2:43:43 PM:   "path": "/edit/",
2:43:43 PM:   "result": {
2:43:43 PM:     "pageContext": {}
2:43:43 PM:   },
2:43:43 PM:   "staticQueryHashes": [
2:43:43 PM:     "3649515864",
2:43:43 PM:     "63159454"
2:43:43 PM:   ]
2:43:43 PM: }
2:43:43 PM: failed Building static HTML for pages - 7.325s
2:43:43 PM: error Building static HTML failed for path "/edit/"
2:43:43 PM: 
2:43:43 PM:   464 |         return authOrCode._errorFactory.create(code, ...fullParams);
2:43:43 PM:   465 |     }
2:43:43 PM: > 466 |     return _DEFAULT_AUTH_ERROR_FACTORY.create(authOrCode, ...rest);
2:43:43 PM:       | ^
2:43:43 PM:   467 | }
2:43:43 PM:   468 | function _assert(assertion, authOrCode, ...rest) {
2:43:43 PM:   469 |     if (!assertion) {
2:43:43 PM: 
2:43:43 PM:   WebpackError: FirebaseError: Firebase: Error (auth/invalid-api-key).
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:466 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:46    6:1
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:470 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:47    0:1
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:5922 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:59    22:1
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:5939 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:59    39:10
2:43:43 PM:   
2:43:43 PM:   - index.esm2017.js:290 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/component/dist/esm/index.esm2017.js:290    :1
2:43:43 PM:   
2:43:43 PM:   - index.esm2017.js:234 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/component/dist/esm/index.esm2017.js:234    :1
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:584 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:58    4:1
2:43:43 PM:   
2:43:43 PM:   - index-62b96d71.js:5988 
2:43:43 PM:     [gatsby-starter-default]/[@firebase]/auth/dist/node-esm/index-62b96d71.js:59    88:1
2:43:43 PM:   
2:43:43 PM:   - edit.js:32 
2:43:43 PM:     gatsby-starter-default/src/pages/edit.js:32:23
2:43:43 PM:   
2:43:43 PM:   - admin.js:25 
2:43:43 PM:     [gatsby-starter-default]/[@grpc]/grpc-js/build/src/admin.js:25:1
2:43:43 PM:   
2:43:43 PM:   - emotion-sheet.esm.js:5 
2:43:43 PM:     [gatsby-starter-default]/[@emotion]/sheet/dist/emotion-sheet.esm.js:5:1
2:43:43 PM:   
2:43:43 PM:   - emotion-sheet.esm.js:10 
2:43:43 PM:     [gatsby-starter-default]/[@emotion]/sheet/dist/emotion-sheet.esm.js:10:1
2:43:43 PM:   
2:43:43 PM:   - seo.js:3 
2:43:43 PM:     gatsby-starter-default/src/components/seo.js:3:1
2:43:43 PM:   
2:43:43 PM:   - static-entry.js:293 
2:43:43 PM:     gatsby-starter-default/.cache/static-entry.js:293:22
2:43:43 PM:   
2:43:43 PM:   - index.esm.js:77 
2:43:43 PM:     [gatsby-starter-default]/[react-icons]/fa/index.esm.js:77:1
2:43:43 PM:   
2:43:43 PM: 
2:43:43 PM: ​
2:43:43 PM: ────────────────────────────────────────────────────────────────
2:43:43 PM:   "build.command" failed                                        
2:43:43 PM: ────────────────────────────────────────────────────────────────
2:43:43 PM: ​
2:43:43 PM:   Error message
2:43:43 PM:   Command failed with exit code 1: npm run build
2:43:43 PM: ​
2:43:43 PM:   Error location
2:43:43 PM:   In Build command from Netlify app:
2:43:43 PM:   npm run build
2:43:43 PM: ​
2:43:43 PM:   Resolved config
2:43:43 PM:   build:
2:43:43 PM:     command: npm run build
2:43:43 PM:     commandOrigin: ui
2:43:43 PM:     publish: /opt/build/repo/public
2:43:43 PM:     publishOrigin: ui
2:43:43 PM:   plugins:
2:43:43 PM:     - inputs: {}
2:43:43 PM:       origin: ui
2:43:43 PM:       package: '@netlify/plugin-gatsby'
2:43:44 PM: Caching artifacts
2:43:44 PM: Started saving node modules
2:43:44 PM: Finished saving node modules
2:43:44 PM: Started saving build plugins
2:43:44 PM: Finished saving build plugins
2:43:44 PM: Started saving pip cache
2:43:44 PM: Finished saving pip cache
2:43:44 PM: Started saving emacs cask dependencies
2:43:44 PM: Finished saving emacs cask dependencies
2:43:44 PM: Started saving maven dependencies
2:43:44 PM: Finished saving maven dependencies
2:43:44 PM: Started saving boot dependencies
2:43:44 PM: Finished saving boot dependencies
2:43:44 PM: Started saving rust rustup cache
2:43:44 PM: Finished saving rust rustup cache
2:43:44 PM: Started saving go dependencies
2:43:44 PM: Finished saving go dependencies
2:43:46 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:43:46 PM: Creating deploy upload records
2:43:47 PM: Failing build: Failed to build site
2:43:47 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
2:43:47 PM: Finished processing build request in 3m35.846230974s

Thank you so much for your time and patience!

Hi @jcgsr,

Did you try to build without cache? If yes, could you try to remove the Gatsby plugin to see if it makes a difference?

Hey @hrishikesh!

Building it without cache worked beautifully.

Thank you so much!