Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rollup] Packaging with Rollup messes up exports #15276

Open
1 task done
hidde-vb opened this issue Feb 26, 2025 · 1 comment
Open
1 task done

[Rollup] Packaging with Rollup messes up exports #15276

hidde-vb opened this issue Feb 26, 2025 · 1 comment
Labels
help wanted help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Milestone

Comments

@hidde-vb
Copy link

hidde-vb commented Feb 26, 2025

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!

@hidde-vb hidde-vb added help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary help wanted labels Feb 26, 2025
@vkarpov15
Copy link
Collaborator

Can you try upgrading to Mongoose 8.4.0, at least locally to see if that fixes the issue? We fixed some rollup bundling issues in #14577 that may help.

@vkarpov15 vkarpov15 modified the milestones: 8.11.1, 8.12.1, 8.12.2 Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted help This issue can likely be resolved in GitHub issues. No bug fixes, features, or docs necessary
Projects
None yet
Development

No branches or pull requests

2 participants