serverless-esbuild icon indicating copy to clipboard operation
serverless-esbuild copied to clipboard

Dependencies of nodeExternals `allowList`ed packages aren't being included in the lambda's node_modules

Open arturenault opened this issue 2 years ago • 2 comments

Describe the bug Dependencies of nodeExternals allowListed packages aren't being included in the lambda's node_modules.

To Reproduce Created a minimal repro here: https://github.com/arturenault/serverless-esbuild-transitive-dep-repro In this repro, service depends on uuid and localPackage. localPackage depends on axios. localPackage is included in the nodeExternals allowList. The package.json files for the root workspace, for localPackage and for service are all passed into the nodeExternals packagePath option.

When I build service, axios is not present in the packaged lambda's package.json or node_modules, but is otherwise treated as external.

This is the generated package.json:

{
  "name": "service",
  "version": "1.0.0",
  "description": "Packaged externals for service",
  "private": true,
  "scripts": {},
  "dependencies": {
    "uuid": "^9.0.0"
  }
}

The bundled code has parts like this. Note how axios is being required:

// ../localPackage/index.ts
var import_axios = __toESM(require("axios"));
var getGoogle = () => import_axios.default.get("www.google.com");

// index.ts
var handler = async () => {
  return {
    statusCode: 200,
    body: getGoogle()
  };
};

Expected behavior Both axios and uuid should end up in the packaged service's package.json and node_modules.

Versions (please complete the following information):

  • OS: [e.g. Linux, Mac, Windows]: Mac
  • Serverless Framework Version: [e.g. 3.0.0]: 3.21.0
  • Plugin Version: [e.g. 1.25.0] 1.37.3

Additional context I'm not entirely sure if this is an issue with nodeExternalsPlugin or with serverless-esbuild. Please let me know if I should open this issue elsewhere!

arturenault avatar Feb 07 '23 21:02 arturenault

What does your serverless.yml file look like? (patterns, and esbuild config, specifically).

jlangsu avatar Feb 09 '23 22:02 jlangsu

From the minimal repro:

https://github.com/arturenault/serverless-esbuild-transitive-dep-repro/blob/main/packages/service/serverless.yml https://github.com/arturenault/serverless-esbuild-transitive-dep-repro/blob/main/packages/service/esbuild.config.js

arturenault avatar Feb 09 '23 23:02 arturenault