Description
Prerequisites
- I have written a descriptive issue title
Mongoose version
6.11.2
Node.js version
18.20.4
MongoDB version
6.8.0
Operating system
macOS
Operating system version (i.e. 20.04, 11.3, 10)
No response
Issue
We are depending heavily on mongoose on our backend. We're having an issue trying to reuse some of the models in a handler with a seperate rollup config, which should be deployed on lambda.
The resulting single transpiled file should contain all dependencies and export a handler function.
However, when introducing mongoose in the code as a dependency, the exports can not be found anymore. When splitting the mongoose code into a seperate chunk, these files are also undefined
.
Error when single bundle file:
"errorType": "Runtime.HandlerNotFound",
"errorMessage": "sms-school-sync.handler is undefined or not exported",
Error when mongoose is bundled seperately:
"errorType": "TypeError",
"errorMessage": "Cannot read properties of undefined (reading 'Schema')",
We're currently experiencing this only with mongoose. For example, bundling Axios in the same file works fine.
Rollup.config.js
:
module.exports = {
// A list of seperate handlers
input: files,
output: {
dir: './dist-lambda',
format: 'cjs',
sourcemap: false,
# Seperate mongoose in its own chunk
manualChunks: id => (id.includes('mongoose') ? 'mongoose' : 'index'),
},
plugins: [
nodeResolve(),
commonjs(),
json(),
typescript({
tsconfig: `${PATH}/tsconfig.json`,
}),
],
external: builtinModules,
};
tsconfig.json
:
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"moduleResolution": "node",
"rootDir": "../../../",
"allowJs": true,
"outDir": "./../../../dist-lambda",
"preserveConstEnums": true,
"sourceMap": true,
"esModuleInterop": true,
"skipLibCheck": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"isolatedModules": true,
},
}
We've tried many different approach but the same problem keeps popping up. Note that our code contains both TS and JS, hence the multiple plugins in our rollup config.
Thanks in advance!