Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log is undefined when plugin is added programatically #602

Closed
ViktorCollin opened this issue Nov 23, 2023 · 1 comment · Fixed by #603
Closed

Log is undefined when plugin is added programatically #602

ViktorCollin opened this issue Nov 23, 2023 · 1 comment · Fixed by #603
Labels

Comments

@ViktorCollin
Copy link

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/[email protected][email protected]/node_modules/serverless-domain-manager/dist/src/logging.js:24:43)
    at ServerlessCustomDomain.<anonymous> (****/node_modules/.pnpm/[email protected][email protected]/node_modules/serverless-domain-manager/dist/src/index.js:180:35)
    at Generator.throw (<anonymous>)
    at rejected (****/node_modules/.pnpm/[email protected][email protected]/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
@rddimon
Copy link
Collaborator

rddimon commented Nov 27, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants