我正在寻找一种方法来简化一些代码并将其提取到自定义的common.js模块中,以使我的Twilio函数更具可读性。
我原以为无服务器api会自动获取自定义js文件,并允许我在需要它的地方使用它,但是在部署之后,它就找不到了。
如果有的话,是否有适当的方法来做以下事情:
const utils = require('./libs/utils.js');
exports.handler = async function(context, event, callback) {
...
utils.do_this();
试着这样做,我想:
{"Message":"Cannot find module './libs/utils.js'\nRequire stack:\n- /var/task/handlers/ZN5be18c53f5acf0299a224607fdeccedb.js\n- /var/task/node_modules/runtime-handler/index.js\n- /var/task/runtime-handler.js\n- /var/runtime/UserFunction.js\n- /var/runtime/index.js","name":"Error","stack":"Error: Cannot find module './libs/utils.js'\nRequire stack:\n- /var/task/handlers/ZN5be18c53f5acf0299a224607fdeccedb.js\n- /var/task/node_modules/runtime-handler/index.js\n- /var/task/runtime-handler.js\n- /...
发布于 2022-06-16 09:37:47
在吐瓦里奥的医生沼泽里游泳,我注意到有关于如何做到这一点的提示。
基本上你必须
utils.js
,请将其重命名为utils.private.js
// notice you don't need to write .private.
const path = Runtime.getAssets()['/utils.js'].path;
exports.handler = async function(context, event, callback) {
const path = Runtime.getAssets()['/utils.js'].path;
const utils = require(path);
https://stackoverflow.com/questions/72649523
复制相似问题