Node.js API 无服务器部署:“记录器未定义”

问题描述 投票:0回答:1

当我离线运行无服务器时,一切正常,当我尝试部署时,出现以下错误:

Stack serverless-auth-dev failed to deploy (6s)

    logger is not defined
    ReferenceError: logger is not defined
    at file:///Users/melifetaji/.serverless/releases/4.0.32/package/dist/sf-core.js:836:742

无服务器.yml

service: serverless-auth

provider:
  name: aws
  runtime: nodejs18.x
  region: eu-central-1
  environment:
    DATABASE_URL: ${env:DATABASE_URL}
    JWT_SECRET: ${env:JWT_SECRET_KEY}

functions:
  app:
    handler: src/api/handler.handler
    events:
      - http:
          path: /
          method: get
          cors: true

plugins:
  - serverless-dotenv-plugin

处理程序.js

  import serverless from 'serverless-http'
   import app from '../../app.js'

   const handler = serverless(app)
   export { handler }

package.json:


{
  "name": "test",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "description": "",
  "dependencies": {
    "express": "^4.19.2",
    "serverless": "^3.38.0",
    "serverless-dotenv-plugin": "^6.0.0",
    "serverless-http": "^3.2.0"
  }
}

为了确保问题不在代码逻辑中,我创建了另一个示例项目,但仍然遇到相同的错误。谢谢!

node.js serverless
1个回答
0
投票

serverless-http
3.1.1
更新为
3.2.0
后,我也遇到了同样的问题。所以我重新安装了旧版本,然后就可以正常工作了。

npm i [email protected]

如果您仍然遇到问题,则可能是由您的插件引起的

© www.soinside.com 2019 - 2024. All rights reserved.