NETLIFY functions: Uncaught Exception: Runtime.ImportModuleError

Viewed 80

I'm running some webhooks on Netlify, but I'm getting an uncaught exception: Runtime.ImportModuleError.

Here is the full error, and you can access a snapshot of the function HERE

{"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'safe-buffer'\nRequire stack:\n- /var/task/src/node_modules/mqtt/lib/connect/ws.js

That is when I import 'async-mqtt', but the problem is that I have another function which uses the exact same import, without any problem. I can reproduce it on another function, but I'm not sure how I can go about reproducing it separately. I'm really lost, so ask if there is any information I need to explain.

Netlify runs on AWS functions, if that can help. Here is the full code of the function:

console.log('at least it opens');
const mqtt = require('async-mqtt');

exports.handler = async function (event, context) {
  const client = await mqtt.connectAsync(
    'mqtts://mqtt.flespi.io', {
      username: 'SECRET HERE',
      port: 8883,
      clientId: `action-on-google--${Math.random().toString(16).substr(2, 8)}`,
    },
  );
  await client.publish('lights/bulbs', 'N255,0');
  client.end();
  return { statusCode: 200, body: 'Hello world' };
};
0 Answers
Related