Firebase-admin-node: Unable to bundle with WebPack 4

Created on 30 Mar 2020  路  3Comments  路  Source: firebase/firebase-admin-node

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS Catalina
  • Firebase SDK version: 8.10.0
  • Firebase Product: n/a
  • Node.js version: v12.16.1
  • NPM version: 6.13.4

[REQUIRED] Step 3: Describe the problem

I'm trying to bundle code with firebase-admin as a dependency, using webpack with a node target (so it can run in AWS Lambda). However, this isn't possible, due to one error:

ERROR in ./node_modules/@firebase/database/dist/index.esm.js
Module not found: Error: Can't resolve '@firebase/app' in '/XXX/node_modules/@firebase/database/dist'
 @ ./node_modules/@firebase/database/dist/index.esm.js 1:0-37 15297:17-25
 @ ./node_modules/firebase-admin/lib/firebase-namespace.js
 @ ./node_modules/firebase-admin/lib/default-namespace.js
 @ ./node_modules/firebase-admin/lib/index.js
 @ ./main.js

I realise you might not consider this a 'bug' as such, but pretty sure this shouldn't be happening given @firebase/app isn't supposed to be a dependency any more?

There is one warning too, in case of interest:

WARNING in ./node_modules/hash-stream-validation/index.js
Module not found: Error: Can't resolve 'fast-crc32c' in 'XXX/node_modules/hash-stream-validation'
 @ ./node_modules/hash-stream-validation/index.js
 @ ./node_modules/@google-cloud/storage/build/src/file.js
 @ ./node_modules/@google-cloud/storage/build/src/index.js
 @ ./node_modules/firebase-admin/lib/storage/storage.js
 @ ./node_modules/firebase-admin/lib/firebase-namespace.js
 @ ./node_modules/firebase-admin/lib/default-namespace.js
 @ ./node_modules/firebase-admin/lib/index.js
 @ ./main.js

Steps to reproduce:

  1. Run webpack against a project with firebase-admin as a dependency

Relevant Code:

main.js:

const firebase = require("firebase-admin");

webpack.config.js:

const path = require('path');

module.exports = {
  entry: './main.js',
  target: "node",
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'main.js'
  }
};
needs-triage

Most helpful comment

yarn add @firebase/app or npm i @firebase/app

All 3 comments

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@firebase/app is a dev dependency. We also have a regular dependency on it via @firebase/database, which is probably how it's getting included in your project:

ERROR in ./node_modules/@firebase/database/dist/index.esm.js
Module not found: Error: Can't resolve '@firebase/app'

We don't have the expertise on Webpack to advise you on this. So you're better off asking around in StackOverflow.

Also look at the following article on using Admin SDK on Lambda via Docker: https://medium.com/@samstern_58566/how-to-use-cloud-firestore-on-aws-lambda-4bf6d3a473d9

yarn add @firebase/app or npm i @firebase/app

Was this page helpful?
0 / 5 - 0 ratings