I'm trying to bundle a project using firebase-admin which will be then deployed to a back end. Everything worked as expected until I added the firebase-admin library, then deploys started failing with the error ReferenceError: require is not defined, which doesn't make sense since the environment the code is being executed in is Node. I've looked up fixes to this but couldn't find much. Here's my Webpack config:
module.exports = {
target: 'node',
externals: [nodeExternals()],
mode: 'production',
entry: './src/index.ts',
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.json$/,
use: 'json-loader',
exclude: /node_modules/,
type: 'javascript/auto'
},
{
test: /\.ts?$/,
use: 'ts-loader',
exclude: /node_modules/,
}
],
},
resolve: {
extensions: ['.ts', '.json'],
},
output: {
filename: 'bundle.js',
path: path.resolve(__dirname, 'lib'),
},
};
Any help is greatly appreciated.