Q:

Unable to use NPM package inside AWS Lambda, require() broken

I have created a very basic NPM package with only two files
index.js:
  module.exports = {
      errors: {
        HttpError: require('./src/errors').HttpError,
        test: 'value'
      }
    }

src/errors.js:
class HttpError extends Error {
  constructor (message, code) {
    super(message)
    this.statusCode = code

    if (Error.captureStackTrace) {
      Error.captureStackTrace(this, HttpError)
    }
  }
}

exports.HttpError = HttpError

When I install this package I can use my error class without any problems. However, when I create a deployment package with Serverless and try to run the code as part of an AWS Lambda, the lambda does not seem to be able to resolve the HttpError class.
In my lambda function running on AWS, when I have required the package as a const and log it out the log looks like this:
{"errors":{"test":"value"}}

whereas locally it looks like:
{ errors:
   { HttpError: [Function: HttpError],
     test: 'value' } }

I have downloaded the deployment package from AWS and can confirm that it looks exactly like the local version. I can't find anything in the lambda docs that imply that I can't use require for javascript modules. What am I doing wrong?

A:

I found the error and it was entirely of my own doing, by making two separate mistakes at the same time. 
I was checking if my package-name.errors.HttpError was an instanceof an identical HttpError class that I had defined in the code that was installing the package, which of course it was not. This lead me to log out the result of the require(), however, I was using JSON.stringify() to do this which of  course will omit functions. Thus I believed that somehow my require() inside the package was not being resolved correctly.

