Search code examples
node.jsserverless

Node.js API serverless deploy: "logger is not defined"


When I run serverless offline, everything works fine, when I try to deploy I get the following error:

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

serverless.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

handler.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"
  }
}

To make sure the problem is not in code logic, I created another sample project, and I still get the same error. Thank you!


Solution

  • The problem was that one necessary permission was missing on the IAM Role, however the log was not displaying correctly because of a bug coming from serverless deploy command.

    The serverless team has been informed, so lets hope they fix this in the future.