无法导入模块' src / index':Function.Module._load出错(module.js:438:3)

时间:2018-05-05 14:32:21

标签: aws-lambda serverless-framework

我使用serverless为TypeScript项目部署了一些更改,我添加了此代码并在其他地方调用它:

import Mixpanel = require('mixpanel')

export default Mixpanel.init(process.env.MIXPANEL_TOKEN)

当我现在调用AWS Lambda函数时,我在日志中收到此错误消息:

  

无法导入模块' src / index':Function.Module._load出错(module.js:438:3)

如何找到有关错误的更多信息?

1 个答案:

答案 0 :(得分:3)

serverless.yml环境变量添加到service: my-service plugins: - serverless-plugin-typescript - serverless-offline - serverless-prune-plugin ... functions: my-function: handler: src/index.default events: - http: path: / method: post environment: MIXPANEL_TOKEN: ${env:MIXPANEL_TOKEN} ... 修复此问题:

fmt.Fprintf(w, page) // Here was the error b/c of the % symbols