amplify-education / serverless-domain-manager

Serverless plugin for managing custom domains with API Gateways.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Log is undefined when plugin is added programatically

ViktorCollin opened this issue Β· comments

Community Note

  • Please vote on this issue by adding a πŸ‘ reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Bug Report

Error Description
If plugin is added via serverless.pluginManager.addPlugin function as part of an other plugin Globals.v3Utils.log becomes undefined

We have an internal plugin that looks like this (some un related parts removed for clarity):

import Serverless from 'serverless';
import Plugin, { PluginStatic } from 'serverless/classes/Plugin';
import { ServerlessCustomDomain } from 'serverless-domain-manager';

class DomainManagerPlugin implements Plugin {
  serverless: Serverless;

  hooks: Plugin.Hooks;

  constructor(serverless: Serverless) {
    this.serverless = serverless;
    this.hooks = {
      initialize: () => this.injectConfig(), // run in hook in case of config needing to be resolved, e.g. shard from params
    };

    // Does not work, need to add the plugin manually, package internal logger breaks for an unknown reason
    serverless.pluginManager.addPlugin(ServerlessCustomDomain as PluginStatic);
  }

  private injectConfig() {
    if (!this.serverless.service.custom) {
      this.serverless.service.custom = {};
    }
    this.serverless.service.custom.customDomain = {
      domainName: 'api.our.domain.com',
      basePath: 'our-base-path',
      stage: '$default',
      apiType: 'http',
      endpointType: 'regional',
      createRoute53Record: false,
      createRoute53IPv6Record: false,
    };
  }
}

If I remove the serverless.pluginManager.addPlugin(...) line and add serverless-domain-manager to the plugin section of serverless.yml everything works as expected

Command Run
sls deploy

Console Output

Stack **** failed to deploy (60s)
Environment: linux, node 18.18.2, framework 3.37.0 (local), plugin 7.2.0, SDK 4.5.1
Credentials: Local, "default" profile
Docs:        docs.serverless.com
Support:     forum.serverless.com
Bugs:        github.com/serverless/serverless/issues

Error:
TypeError: Cannot read properties of undefined (reading 'verbose')
    at Logging.logInfo (****/node_modules/.pnpm/serverless-domain-manager@7.1.2_serverless@3.37.0/node_modules/serverless-domain-manager/dist/src/logging.js:24:43)
    at ServerlessCustomDomain.<anonymous> (****/node_modules/.pnpm/serverless-domain-manager@7.1.2_serverless@3.37.0/node_modules/serverless-domain-manager/dist/src/index.js:180:35)
    at Generator.throw (<anonymous>)
    at rejected (****/node_modules/.pnpm/serverless-domain-manager@7.1.2_serverless@3.37.0/node_modules/serverless-domain-manager/dist/src/index.js:6:65)
    
Error: Process completed with exit code 1.

Domain Manager Configuration
Replace this with your own serverless.yml file (anonymized, of course) to help us better resolve your issue.

custom:
  customDomain:
      domainName: 'api.our.domain.com',
      basePath: 'our-base-path',
      stage: '$default',
      apiType: 'http',
      endpointType: 'regional',
      createRoute53Record: false,
      createRoute53IPv6Record: false,

Versions

  • Domain Manager version(s): 7.1.2
  • Node/npm version: 18.18.2
  • Serverless Version: 3.37.0
  • Lambda Code TypeScript/JavaScript

Hi @ViktorCollin

Due to the serverless logic here we will get an object with properties or an empty project
The PR linked above should fix it