无法导入模块 'src/index':Function.Module._load 处出错 (module.js:438:3)
Unable to import module 'src/index': Error at Function.Module._load (module.js:438:3)
我使用 serverless
对 TypeScript 项目部署了一些更改,我添加了这段代码并在别处调用它:
import Mixpanel = require('mixpanel')
export default Mixpanel.init(process.env.MIXPANEL_TOKEN)
当我现在调用 AWS Lambda 函数时,我在日志中收到此错误消息:
Unable to import module 'src/index': Error at Function.Module._load (module.js:438:3)
如何找到有关该错误的更多信息?
将 MIXPANEL_TOKEN
环境变量添加到 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}
...
我使用 serverless
对 TypeScript 项目部署了一些更改,我添加了这段代码并在别处调用它:
import Mixpanel = require('mixpanel')
export default Mixpanel.init(process.env.MIXPANEL_TOKEN)
当我现在调用 AWS Lambda 函数时,我在日志中收到此错误消息:
Unable to import module 'src/index': Error at Function.Module._load (module.js:438:3)
如何找到有关该错误的更多信息?
将 MIXPANEL_TOKEN
环境变量添加到 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}
...