Skip to content

Package does not work depending how the consumer is bundled #79

@jose-garrido-martinez

Description

@jose-garrido-martinez

Steps to reproduce

  • Create an empty serverless project for typescript: (after installing typescript, run serverless create --template aws-nodejs-typescript --path aws-serverless-typescript-api
  • Install the package
  • In the hello-world function created by the template, add the next code (with the required import): validate('US', '12345')
  • Run the function (serverless offline)
  • It will throw with the error: Cannot find module '/Users/e10117069/Code/MS/address-management-purchase-api/.esbuild/.build/src/functions/helloWorld/formats/US.json'\nRequire stack:\n- /Users/e10117069/Code/MS/address-management-purchase-api/.esbuild/.build/src/functions/v1/helloWorld/handler.js\n- /Users/e10117069/Code/MS/address-management-purchase-api/node_modules/serverless-offline/src/lambda/handler-runner/in-process-runner/aws-lambda-ric/UserFunction.js

Problem

As serverless builds the required dependencies in just on output file and it tries to obtain the json files from the root folder of the output.

Workaround 1

  • Add and configure webpack to add the json files to the root folder of the function.

Possible solution

Allowing to force using the format web (that adds the files with require, so they are included in the bundle). Added pull request: #78

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions