Functions can not find node modules in new builds

We hadn’t deployed our site in a few months (end of June/early July). We made a minor text change to the site (no changes to the functions code) a few days ago and after the deploy we’re seeing the following error in our Netlify functions:

ERROR Uncaught Exception {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module '@aws-sdk/client-dynamodb'\nRequire stack:\n- /var/task/netlify/functions/includes/dynamodb.js\n- /var/task/netlify/functions/includes/visa/visa.js\n- /var/task/netlify/functions/validateApplication.js\n- /var/task/validateApplication.js\n- /var/runtime/index.mjs","stack":["Runtime.ImportModuleError: Error: Cannot find module '@aws-sdk/client-dynamodb'","Require stack:","- /var/task/netlify/functions/includes/dynamodb.js","- /var/task/netlify/functions/includes/visa/visa.js","- /var/task/netlify/functions/validateApplication.js","- /var/task/validateApplication.js","- /var/runtime/index.mjs"," at _loadUserApp (file:///var/runtime/index.mjs:1087:17)"," at async Object.UserFunction.js.module.exports.load (file:///var/runtime/index.mjs:1119:21)"," at async start (file:///var/runtime/index.mjs:1282:23)"," at async file:///var/runtime/index.mjs:1288:1"]}

We’ve done some digging through forum posts, tried re-deploying several branches of code etc., but to no avail. We’re a bit stuck trying to figure out why the same code deployed just a few months is no longer working.

Comparing deployments in our site, as best we can tell the only difference between (working) code deployed a few months ago and (failing) code deployed now is the version of @netlify/build.

These is a snippet from our package.json:

  "dependencies": {
    "axios": "^0.26.1",
    "dotenv": "^16.0.0",
    "font-awesome": "^4.6.3",
    "jquery": "^1.9.1",
    "lodash": "^4.17.21",
    "popper.js": "^1.16.1",
    "qs": "^6.10.3",
    "soap": "^0.43.0",
    "uuid": "^8.3.2"

We’ve also tried upgrading the version of Node and upgrading some of the node package versions. Even then we get a Cannot find module error (for the ‘soap’ module).

Please help!

I don’t see @aws-sdk listed in your package.json. Have you installed the dependency?