0

错误信息

undefined ERROR Uncaught Exception  {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'tslib'"}

文件夹结构

源代码

  • handler.ts -> fn.getAll

模板.yaml

GetAll:
Type: AWS::Serverless::Function
Properties:
  Handler: handler.getAll
  CodeUri: dist/out-tsc
  Policies:
    - DynamoDBCrudPolicy:
        TableName: !Ref master
  Environment:
    Variables:
      USE_EVENT_BRIDGE: !Ref UseEventBridge
  Events:
    Api1:
      Type: Api
      Properties:
        Path: /getAll
        Method: get

导出目录:

dist/out-tsc

  • handler.js -> fn.getAll

使用 tsc 进行 typescript 编译后。输出文件在目标位置生成。在每个 JS 处理程序文件中,我都有 tslib require 语句。下面的错误消息表示相同。当我单击 tslib 时,它完美地引用了节点模块。我该如何克服呢?

tsconfig.json在编译器选项中更新了以下选项。在节点模块中安装 tslib

"paths": {
  "tslib": ["node_modules/tslib/tslib.d.ts"]
}

错误:

START RequestId: 820d8905-61f3-4045-9704-3cc7bd4901df Version: $LATEST
2021-02-12T11:18:32.904Z
undefined   ERROR   Uncaught Exception  {"errorType":"Runtime.ImportModuleError","errorMessage":"Error: Cannot find module 'tslib'","stack":["Runtime.ImportModuleError: Error: Cannot find module 'tslib'","
    at _loadUserApp (/var/runtime/UserFunction.js:100:13)","
    at Object.module.exports.load (/var/runtime/UserFunction.js:140:17)","    
    at Object.<anonymous> (/var/runtime/index.js:45:30)","
    at Module._compile (internal/modules/cjs/loader.js:778:30)","
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)","
    at Module.load (internal/modules/cjs/loader.js:653:32)","
    at tryModuleLoad (internal/modules/cjs/loader.js:593:12)","
    at Function.Module._load (internal/modules/cjs/loader.js:585:3)","
    at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)","
    at startup (internal/bootstrap/node.js:283:19)"]}
4

0 回答 0