-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
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
Cannot find module './drivers/node-mongodb-native/connection' using Parcel #9603
Comments
setDriver()
function on Mongoose instance instead
We definitely want to remove MONGOOSE_DRIVER_PATH in the next major release. However, removing it before then is very risky and may break other people's code because MONGOOSE_DRIVER_PATH has been supported for about 8 years at this point. We use it internally to make sure we avoid the node driver so we can build Mongoose's browser library. Until then, you'll have to find a workaround with parcel to pull in the missing files. I don't know enough about parcel yet to suggest a workaround, but I'll look into it later this week. |
setDriver()
function on Mongoose instance instead
Thank you! Parcel isn't able to manually require the missing files. Nonetheless, thanks for picking this up! |
Hitting this with https://esbuild.github.io as well. @julescubtree did you find a work around for this ever? |
I am using esbuild through aws-lambda-nodejs. Noticed some warnings due to dynamic requires which resulted in runtime errors. For logform I followed evanw/esbuild#480 (comment) but for mongoose I used patch-package to modify: /lib/index.jsLines 7 to 16 in 1c2978e
Lines 725 to 741 in 1c2978e
It is not ideal but works. I also extended NodejsFunction to avoid having to apply these workarounds for each lambda that needs them. Used hooks, fs, and spawnsync in the implementation. |
@hugdru Could you share your patched code? I am having the same problem with |
@CryogenicPlanet Yeah sure. I followed the steps in patch-package which resulted in patches/mongoose+5.10.19.patch in the root of the project. https://gist.github.com/hugdru/982a31d929a030e29f852c4bfafd9b16 |
thx @hugdru for your suggested changes! We could use those in our project. Since we are also effected by typegoose/typegoose#480 and therefore need mongoose version
|
I took a closer look at this and we may be able to work around this in Mongoose 5.x without breaking the API completely. We'll review a bit more but otherwise we should be able to release this fix with Mongoose 5.12.8 👍 |
Fix will be in 5.12.8 👍 |
Do you want to request a feature or report a bug?
bug
What is the current behavior?
I'm using parcel v2 to bundle an entire node api into one JS file.
It's a relatively small api, and i need to bundle all of it because of the hosting env it will ultimately be placed on.
The API uses mongoose and when it's bundled & 'compiled' by parcel it doesn't raise any errors. However, when running the application it doesn't work because certain parts of mongoose are missing, that's where the error "Cannot find module './drivers/node-mongodb-native/connection'" comes from. The runtime environment can't find this module because it's never bundled.
The cause of this problem has been found in other issues from other libraries. See:
parcel-bundler/parcel#4031
evanw/esbuild#480
The esbuild issue is from a different library, but it boils down to the same problem.
Some parts of mongoose are required dynamically using a variable. See:
mongoose/lib/index.js
Lines 729 to 735 in 1c2978e
The bundlers don't pick this up and this results in those parts not being bundled, and therefore not being available at runtime.
If the current behavior is a bug, please provide the steps to reproduce.
To reproduce this issue, i've included a sample project below. Just use "npm run start" to see the error.
The source files
What is the expected behavior?
I would expect to see all modules that are needed to be bundled.
A way to achieve this would be to not use a dynamic require. I saw the global.MONGOOSE_DRIVER_PATH is being deprecated anyway. Maybe this issue could be addressed in the next release?
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version.
The text was updated successfully, but these errors were encountered: