Skip to content

Commit e80a940

Browse files
authored
chore(aws-serverless): Fix local cache issues (#19081)
Most of the times `@sentry/aws-serverless:build:transpile` was failing locally: <img width="1146" height="398" alt="Screenshot 2026-01-29 at 12 24 00" src="https://github.com/user-attachments/assets/a51974c4-dd7f-4701-b61f-229c59b5a284" /> I now had some time to investigate on it. It seems that the caching is sometimes not working pretty nicely with yarn if you have add another working directory. With the power of `--cache-folder` we can temporarily give another cache folder and mitigate the problem. In total the fix is not ideal and more of a band-aid solution. If there are other ideas I'm fully up for it.
1 parent 9de002b commit e80a940

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

packages/aws-serverless/scripts/buildLambdaLayer.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { nodeFileTrace } from '@vercel/nft';
33
import * as childProcess from 'child_process';
44
import * as fs from 'fs';
5+
import * as os from 'os';
56
import * as path from 'path';
67
import { version } from '../package.json';
78

@@ -23,11 +24,19 @@ async function buildLambdaLayer(): Promise<void> {
2324
console.log('Building Lambda layer.');
2425
buildPackageJson();
2526
console.log('Installing local @sentry/aws-serverless into build/aws/dist-serverless/nodejs.');
26-
run('yarn install --prod --cwd ./build/aws/dist-serverless/nodejs');
27+
// Use a temporary cache folder to avoid stale cache references to local file: packages.
28+
// Yarn's global cache can contain outdated references to build artifacts from other
29+
// @sentry/* packages (e.g., build/node_modules paths that no longer exist), causing
30+
// ENOENT errors during file copying.
31+
// The cache folder must be outside the monorepo to avoid recursive nesting when Yarn
32+
// follows file: links and copies package directories.
33+
const cacheFolder = path.join(os.tmpdir(), `sentry-lambda-build-cache-${Date.now()}`);
34+
run(`yarn install --prod --cwd ./build/aws/dist-serverless/nodejs --cache-folder "${cacheFolder}"`);
2735

2836
await pruneNodeModules();
2937
fs.rmSync('./build/aws/dist-serverless/nodejs/package.json', { force: true });
3038
fs.rmSync('./build/aws/dist-serverless/nodejs/yarn.lock', { force: true });
39+
fs.rmSync(cacheFolder, { recursive: true, force: true });
3140

3241
// The layer also includes `awslambda-auto.js`, a helper file which calls `Sentry.init()` and wraps the lambda
3342
// handler. It gets run when Node is launched inside the lambda, using the environment variable

0 commit comments

Comments
 (0)