Function is unable to find dependency

I have tried every stitch of documentation I could find on this issue, and the resolution still evades me. I’m trying to write a simple function that verifies user login information based on an existing collection.

  1. I have added the dependency with the “Add Dependency” button
  2. I have uploaded the node_modules folder.
  3. I have pulled the app with the cli, installed the dependency and pushed it up that way.

In all instances you can see the dependency on the dependency tab, but the function refuses to find it. I just keep getting this error:

failed to execute source for 'node_modules/argon2/argon2.js': TypeError: Value is not an object: undefined
	at node_modules/@mapbox/node-pre-gyp/lib/pre-binding.js:29:18(4)
	at node_modules/argon2/argon2.js:34:30(93)

super simple function that is trying to use it, with sensitive information removed of course:

exports = async (loginPayload) => {
    const argon2 = require('argon2');
    
    let response;

    
  const user = await context.services.get("mongodb-atlas").db("database").collection("collection").find({email: loginPayload.email}).toArray();
  
  
  if(!user) {
    response = {
      message: 'User not found',
      status: 400
    }
    
    return JSON.stringify(response);
  } 
  
  const verify = await argon2.verify(loginPayload.password, user.password);
  if(!verify) {
    response = {
      message: "Invalid username or password",
      status: 400
    }
    
    return JSON.stringify(response);
  }
  
  
  return {message: 'authenticated', user: JSON.stringify(user)};
  };

I could really use some good juju here if anyone has any… that is of course actually working.

Curious whether you ended up resolving this? I’m having the exact same issue (different dependency though) where the dependency is added on the dependency tab but I get that error when the function is run

hey @Campbell_Affleck , No I didn’t sorry man. I ended up ditching it and going a different direction all together. I’m using supabase now.

No worries, thanks for the quick response! I’ll give supabase a look.

For anyone stumbling on this, I think the error was due to the dependency requiring a more recent Node.js version. As far as I can tell, the Atlas function environment is still stuck using v10, which the current versions of a lot of dependencies are no longer compatible with (argon2 requires v14). In my case (using mailgun.js), I was able to get past this specific error by specifying an outdated mailgun version, but with newer dependencies you might not have that option.