I also got the same issue
hi @taitheexplore @kristina71103, I’ve routed this internally as I don’t have an immediate answer, but I’ll get back to you soon.
Thanks
I also got same error, cannot find any solution for this, what we can do? Below mentioned fully detailed error stack from Webtask Logs.
Hello everyone, facing the exact same issue here:
[SandboxUnhandledError] Cannot find module ‘mongodb@3.1.4’
Require stack: - /data/io/node18/5777205b-486a-478a-a40a-e11cbb127480/webtask.js
I tried the alternatives mentioned above but none of them work for my case as well. Is there any updates ?
Hi @marialena @buddhins @taitheexplore,
The issue seems related to the version of NodeJS you are running in your tenant (you can check your version here: https://manage.auth0.com/#/tenant/advanced).
The following versions of mongodb drivers are available for the following NodeJS versions:
- NodeJS 18
- 5.1.0
- 5.7.0
- NodeJS 16
- 3.5.11
- 3.1.4
- 2.1.11
If you want to check other packages or other versions of node, please check out the following page:
https://auth0-extensions.github.io/canirequire/
By adjusting the right mongo driver to match your tenant’s NodeJS version your issue gets fixed.
Thanks
Thank you @bajcmartinez . Error fixed. In my tenant, it used Node 18, then I changed it to NodeJS 16 and import mongodb version 4.1.0 version (const MongoClient = require(‘mongodb@4.1.0’).MongoClient;). Now it works without any error.
That’s great @buddhins, thanks for replying back with the confirmation. I’ll make changes on the article so that this topic is address.
Have a great day!
Posting this information everywhere that I see Node 18 and people rolling back to 16.
Auth0 Engineering replied to my inquiry and responded with this:
To use version 5 of the mongo driver, you should update your script to use promises. Here’s an example get_user script you can reference.
function getByEmail(email, callback) {
const MongoClient = require('mongodb').MongoClient;
const client = new MongoClient(configuration.URL);
(async () => {
try {
await client.connect();
const db = client.db(configuration.DB);
const users = db.collection('users');
const user = await users.findOne({ email: email });
if (!user) return callback(null, null);
return callback(null, {
user_id: user._id.toString(),
nickname: user.nickname,
email: user.email
});
} catch(e) {
return callback(e);
} finally {
await client.close();
}
})();
}
I can confirm this works and fixes the problem. I’m able to use latest Mongo 5.x client and Node 18.