Realm Functions importing dependencies: Cannot find module 'module-name'

Hello :wave:

I have been working with functions and have set up a dependecies archive as specified here: https://docs.mongodb.com/realm/functions/upload-external-dependencies/

I followed the instructions to import them from here:https://docs.mongodb.com/realm/functions/import-external-dependencies/
For some reason, the .tar file did not work so I had to use .zip.
The modules show up on the UI, however importing them yields the error Cannot find module 'module-name'.

I have tried both the UI upload and through realm-cli.

Here are some screenshots:

16-02-2021 08-26-08 a.m.

16-02-2021 08-16-54 a.m.

I just tested it out using this function and it worked for me:

exports = function () {
  const ajv = require("ajv");
  console.log("Made it this far");
  console.log(JSON.stringify(ajv, null, 4));
  
  return "All good";
}

I created the gz file with:

npm install ajv
tar -czf node_modules.tar.gz node_modules

Just to check – did you “REVIEW & DEPLOY” after uploading the modules?

1 Like