serverless-esbuild
serverless-esbuild copied to clipboard
Dependencies of nodeExternals `allowList`ed packages aren't being included in the lambda's node_modules
Describe the bug
Dependencies of nodeExternals allowList
ed 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 require
d:
// ../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!
What does your serverless.yml file look like? (patterns, and esbuild config, specifically).
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