Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
89 views
in Technique[技术] by (71.8m points)

javascript - NETLIFY functions: Uncaught Exception: Runtime.ImportModuleError

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'
Require stack:
- /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' };
};
question from:https://stackoverflow.com/questions/65910129/netlify-functions-uncaught-exception-runtime-importmoduleerror

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...