Update: It seems that there might be a deeper issue at play here, unrelated to the import of lodash.
It appears that within the codebase I inherited, the function cloneDeep is being used in multiple instances, and it's possible that there is a circular reference causing problems with the cloning process. If this is indeed the case, I will address this issue and likely encounter some other issues along the way.
nodeJS | v14.20.0 |
typescript | v4.6.4 |
mongodb | v4.9.1 |
mongoose | v6.6.1 |
connect-mongodb-session | v3.1.1 |
lodash | v4.17.21 |
During an upgrade process across various levels, the main obstacle encountered was configuring and connecting to MongoDB using mongoose while switching from connect-mongo to connect-mongodb-session. The build completed without errors, but running the application led to the following:
/Users/.../node_modules/lodash.clonedeep/index.js:841
function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
^
RangeError: Maximum call stack size exceeded
at baseClone (/Users/.../node_modules/lodash.clonedeep/index.js:841:19)
at /Users/.../node_modules/lodash.clonedeep/index.js:897:30
...
This error occurred during mongoose configuration:
import mongo from 'connect-mongodb-session';
import mongoose from './db'
const MongoStore = mongo(session);
...
const sessionMongoStore = new MongoStore({
autoReconnect: true,
mongooseConnection: mongoose.connection
});
app.use(
session({
secret: 'Pnv68aFuBy',
store: sessionMongoStore,
resave: true,
saveUninitialized: true,
})
);
The db.ts file extends mongoose to provide a properly configured connection and contains the following:
import assert from 'assert';
import mongoose from 'mongoose';
import appEnv from './appenv';
import bluebird from 'bluebird';
import * as _ from 'lodash';
(mongoose as any).Promise = bluebird;
...
mongoose.connect( connectionString)
.then( () => { /* resolves to undefined */})
.catch(err => {
console.log('MongoDB connection error: ' + err);
});
export default mongoose;
All of this was functioning correctly with the previous versions listed below:
nodeJS | v12.22.12 |
typescript | v3.8.3 |
mongodb | v3.3.13 |
mongoose | v5.9.12 |
connect-mongo | v3.1.2 |
lodash | v4.17.13 |
I am considering whether including the db.ts file is causing an infinite recursion issue for lodash.