首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无服务器包缺少依赖项

无服务器包缺少依赖项
EN

Stack Overflow用户
提问于 2021-11-13 08:52:54
回答 1查看 433关注 0票数 1

我无法用无服务器包插件生成包。

tsconfig.json

代码语言:javascript
复制
{
 "compilerOptions": {
    "lib": ["es2017"],
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,

    "target": "es2017",
    "outDir": "dist",
    "declaration": true,
    "sourceMap": true,
    "baseUrl": ".",

    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "allowJs": false,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true
  },
  "exclude": ["./dist/**/*", "./node_modules/**/*"]
}

serverless.yml

代码语言:javascript
复制
service: serverless-boilerplate

custom:
  # Our stage is based on what is passed in when running serverless
  # commands. Or falls back to what we have set in the provider section.
  stage: ${opt:stage, 'offline'}
  region: ${opt:region, 'us-east-1'}
  bundle:
    linting: false
  serverless-offline:
    httpPort: 4000
    noPrependStageInUrl: true

provider:
  name: aws
  runtime: nodejs14.x
  memorySize: 512
  timeout: 10
  logRetentionInDays: 90
  lambdaHashingVersion: 20201221 # https://www.serverless.com/framework/docs/deprecations/#LAMBDA_HASHING_VERSION_V2
  logs:
    httpApi: true
  httpApi:
    # metrics: true # Enable if you need
    cors: true

functions:
  app:
    handler: src/handler.handler
    # reservedConcurrency: 100
    events:
      - httpApi:
          path: '/{proxy+}'
          method: '*'

package:
  individually: true

plugins:
  - serverless-dotenv-plugin
  - serverless-bundle
  - serverless-offline

以下是运行.serverless/app.zip后的sls package文件

正如您所看到的,没有node_modules文件夹。

如果我用sls offline start --stage offline启动这个应用程序

它看起来像是试图在node_modules中自己的包文件夹中读取目录(资源)的依赖关系之一:

但是由于serverless-bundle将所有内容合并到handler.js中,所以没有node_modules文件夹和依赖文件夹,所以readdir()失败了。

我做错什么了?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-11-13 09:27:07

看起来,将externals: all添加到serverless.yml中的custom.bundle解决了这个问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69952799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档