Haseeb Naseem
11/15/2021, 12:23 PMexternalModules
property in the function bundle definition is not applied. For example here:
https://github.com/serverless-stack/serverless-stack/blob/master/packages/cli/scripts/start.js#L768
To get the esbuild external modules, the externalModules property is not taken into account.
async function getEsbuildExternal(srcPath) {
let externals;
try {
const packageJson = await fs.readJson(path.join(srcPath, "package.json"));
externals = Object.keys({
...(packageJson.dependencies || {}),
...(packageJson.devDependencies || {}),
...(packageJson.peerDependencies || {}),
});
} catch (e) {
logger.warn(`No package.json found in ${srcPath}`);
externals = [];
}
// Always include "aws-sdk" in externals
// Note: this helps with the case where "aws-sdk" is not listed in the srcPath's
// package.json. It could be in parent directories' package.json.
//
// Example 1: the SST app is a package inside a yarn workspace, and
// "aws-sdk" is in repo root's package.json.
// Example 2: the SST app is at the repo root, but the Lambda function has
// a srcPath. And "aws-sdk" is in repo root's package.json.
//
// The long term fix is to run `esbuild` and if the input files contain
// "node_modules/XYZ", kill the esbuild service. And remember "XYZ". And
// the next time the function gets invoked, start a new esbuild process,
// and set "XYZ" as an external. Need to check other packages in the Yarn
// workspace do not show up as "node_modules" in the input files. Because
// we want them to be included in input files and watch them.
if (!externals.includes("aws-sdk")) {
externals.push("aws-sdk");
}
return externals;
}
Haseeb Naseem
11/15/2021, 12:41 PMpg
to connect to postgresql but sst start complains about missing pg-native
which is an optional dependency and is not needed. This does not get solved after adding pg-native
to externalModules in the function’s bundle properties.Frank
node_modules/@serverless-stack/cli/scripts/start.js
, find the getEsbuildExternal()
funciton.Frank
return externals;
add
externals.push("pg-native");
Frank
thdxr
11/15/2021, 5:36 PMthdxr
11/15/2021, 5:47 PMHaseeb Naseem
11/16/2021, 4:54 AMexternals.push("pg-native");
Haseeb Naseem
11/16/2021, 4:56 AMthdxr
11/16/2021, 4:56 AMHaseeb Naseem
11/16/2021, 5:00 AMFrank
pg-native
is an optional dependency and not required in ur code, why is esbuild trying to bundle it?Frank
pg-native
in your package.json
by any chance?Frank
thdxr
11/16/2021, 10:54 PMHaseeb Naseem
11/17/2021, 7:08 PMthdxr
11/17/2021, 7:09 PM