该错误通常发生在有些Lambda函数中,这些函数使用了旧版的Synthetic Canary。解决方法是更新函数代码以使用最新版的Synthetic Canary。以下是示例代码:
旧版代码:
const synthetics = require('Synthetics'); const { exports } = require('/opt/nodejs/node_modules/exports'); const log = require('/opt/nodejs/node_modules/log');
const canary = synthetics.createCanary('MyCanary', async function () { // Your code here });
新版代码:
const synthetics = require('Synthetics'); const log = require('/opt/nodejs/node_modules/log');
const canary = synthetics.createCanary('MyCanary', async function () { // Your code here });
在新版代码中,只需移除旧版代码中的exports的引用即可。这样一来,就不会再出现“无法找到模块‘/opt/nodejs/node_modules/exports’”的错误了。