【发布时间】:2018-04-17 20:15:40
【问题描述】:
一个错误是:
"errorMessage": "Cannot find module './dist/commonjs/index.js'",
另一个错误是:
Unable to import module 'index': Error
at Function.Module._resolveFilename (module.js:469:15)
我看过关于第二个错误的其他帖子,但我已经完成了他们推荐的所有操作,但仍然卡住了。他们没有提到 /dist/commonjs/index.js 问题。
我的 Lambda 函数处理程序设置为“index.handler”,我的主要代码在 index.js 中。
我在 Windows 上。我的 zip 文件 (HebrewVocab.zip) 看起来像这样。 而 node_modules 文件夹似乎是完整的,看起来像这样: 我用我写的 PowerShell 压缩并上传:
Compress-Archive -Path index.js,package.json,node_modules -DestinationPath $ZipFileName
aws lambda update-function-code --function-name HebrewVocab --zip-file
fileb://HebrewVocab.zip
我的 index.js 以这段代码开头:
exports.handler = function(event, context, callback) {
var alexa = Alexa.handler(event, context, callback);
alexa.registerHandlers(handlers);
alexa.execute();
};
所以我似乎满足了我在类似错误的所有其他帖子中阅读的所有要求。我之前有一个 HelloWorld 项目工作,但它没有使用 alexa-sdk。
我也按照 Stackoverflow 上的一个人的建议执行了“npm install npm”?有必要吗?
当我在 Lamba 中“测试”时,与使用 Alexa 语音测试相比,我看到了细节:
"errorMessage": "Cannot find module './dist/commonjs/index.js'",
./dist/commonjs 应该是标准路径前缀吗?我什至已经将“函数”导出到我的硬盘驱动器(作为.zip),这正是我上传的),并且.zip 文件的根目录中肯定有一个 index.js。
作为一个疯狂的猜测,我发现 commonjs 是一个包,所以我做了一个“npm install commonjs --save”,重新压缩并重新上传,但结果完全相同。
我后来发现有一个带有 index.js 的 /node_modules/i18next/dist/commonjs,但不确定这是否相关。我什至尝试将 dist/commonjs 复制到我的根目录和 node_modules 下,但仍然是同样的错误。
当我在本地运行时它运行良好:
lambda-local -l index.js -h handler -e eventHelloWorld.json
最后但同样重要的是,我的 package.json 看起来像这样:
{
"name": "HebrewVocab",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {
"alexa-sdk": "^1.0.18",
"commonjs": "0.0.1",
"npm": "^5.5.1"
},
"devDependencies": {},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC"
}
我还能尝试什么?我在亚马逊支持论坛上发帖,但没有答案,所以我的项目被卡住了,直到我弄清楚了。
2017 年 11 月 7 日更新:
好的,我刚刚做了一个疯狂的观察。由上述 Powershell 创建的 .zip 创建的 .zip 大小与 Windows 右键单击“发送到”压缩文件夹不同。如果我使用 Total Command“同步目录”比较两个 zip,所有文件和结构的内容都是相同的。然而,从手动 Windows zip 创建的一个有效,而由 Powershell 创建的一个给出了最初在该线程中报告的错误。 Powershell 创建的 5,019,123 比 5,032,770 略小。我尝试了其他一些 powershell 压缩选项,但它们创建了更大的文件(关闭它会产生大约 30 MB 的文件)。
我已经进入了暮光区——有什么想法吗?
【问题讨论】:
标签: aws-lambda alexa alexa-skills-kit