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

"Error: Cannot find module './drivers/node-mongodb-native/connection'" when used with optimize #85

Open
sebastiangug opened this issue Aug 30, 2019 · 5 comments

Comments

@sebastiangug
Copy link

Stackoverflow thread here.

I've also added mongoose as a separate layer with all of its dependencies, it throws the exact same error. Is there something special I have to config somewhere to get this to work?

On the list of third-party modules this is supposed to work with, mongoose must be quite high as it is the most popular choice for mongodb via node.

@sebastiangug
Copy link
Author

sebastiangug commented Aug 30, 2019

I've just bundled my app with the serverless-plugin-monorepo and it works, but my bundle is 40mb instead of 2 so that's not cool. If I exclude 'mongoose' using the custom -> optimizer -> exclude: ['mongoose'] I don't get that error but I do get the following error:

    "errorType": "Error",
    "errorMessage": "ENOENT: no such file or directory, 
     scandir '/var/task/_optimize/tlabs-api-dev-main/src/node_modules/pkginfo'",
    "code": "ENOENT",
    "stack": [

Am i correct to assume that package is not being bundled correctly with the whole thing? I couldn't find any reason why that dependency is even there though.

@sebastiangug
Copy link
Author

Managed to exclude mongoose successfully. The second error was for a crappy dependency of another package, I changed that package with something else that doesn't have those dependencies, now getting:

 "errorType": "Runtime.ImportModuleError",
    "errorMessage": "Error: Cannot find module './stores/memory'",

Is this really optimizing anything at all if I have to manually remove a bunch of dependencies that break the whole thing?

@maazmk
Copy link

maazmk commented Jul 30, 2020

any update on this?

@sebastiangug
Copy link
Author

Yeah, the update is to stop using serverless for deploying any kind of serious infrastructure

@dhiraj-indusved
Copy link

Anyone coming here for Error: Cannot find module './drivers/node-mongodb-native/connection

I found a solution here Automattic/mongoose#9603 , thanks to hugdru

The problem is some parts of mongoose are required dynamically using a variable. One can use https://www.npmjs.com/package/patch-package to create a temporary patch until the next major release of mongoose where this is going to be fixed.

Changes to be made in node_modules/mongoose/lib/index.js with the changes given here https://gist.github.com/hugdru/982a31d929a030e29f852c4bfafd9b16 and the. just run yarn patch-package mongoose

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants