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
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'
}
};
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
Most helpful comment
yarn add @firebase/appornpm i @firebase/app