我正在尝试为alexa做我的第一项技能,我正在使用aws lambda进行逻辑,我的问题是,当我运行测试时,它会返回给我:
{
"errorMessage": "Cannot find module 'string-similarity'",
"errorType": "Error",
"stackTrace": [
"Function.Module._load (module.js:474:25)",
"Module.require (module.js:596:17)",
"require (internal/module.js:11:18)",
"Object.<anonymous> (/var/task/index.js:3:24)",
"Module._compile (module.js:652:30)",
"Object.Module._extensions..js (module.js:663:10)",
"Module.load (module.js:565:32)",
"tryModuleLoad (module.js:505:12)",
"Function.Module._load (module.js:497:3)"
]
}我需要字符串相似性来比较两个字符串,但我不知道如何在lambda中安装它。
这是我的package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"alexa",
"skill"
],
"author": "",
"license": "",
"dependencies": {
"ask-sdk": "^2.0.0",
"string-similarity": "^1.2.0",
"i18next": "^10.6.0",
"i18next-sprintf-postprocessor": "^0.2.2"
}
}所以我在index.js中调用这个包
'use strict';
const Alexa = require('ask-sdk');
var stringSimilarity = require('string-similarity');
...如何解决此错误?
谢谢你的帮助,很抱歉我的英语,但我不是以英语为母语的人。
发布于 2018-12-07 13:21:02
你得到这个错误是因为你正在使用'string-similarity‘,但是你没有在你的项目中安装它,这就是为什么它会给你一个"errorMessage":“无法找到模块’字符串相似性‘”。
不能直接在Lambda函数中添加节点模块。如果你需要使用外部模块/库,你需要将你的项目放在本地机器上,这样你就可以安装npm,安装所需的模块,然后在中上传你项目的.ZIP文件,请参阅。
或者,您可以使用、ASK CLI、来编写代码,使用您选择的某个编辑器,然后使用简单的命令部署lambda函数。
https://stackoverflow.com/questions/53573903
复制相似问题