@@ -22,6 +22,8 @@ function run(cmd: string, options?: childProcess.ExecSyncOptions): string {
2222async function buildLambdaLayer ( ) : Promise < void > {
2323 console . log ( 'Building Lambda layer.' ) ;
2424 buildPackageJson ( ) ;
25+ // Clean up Angular ngcc lock files that can cause yarn install to fail when using file: dependencies
26+ cleanupNgccLockFiles ( ) ;
2527 console . log ( 'Installing local @sentry/aws-serverless into build/aws/dist-serverless/nodejs.' ) ;
2628 run ( 'yarn install --prod --cwd ./build/aws/dist-serverless/nodejs' ) ;
2729
@@ -153,6 +155,31 @@ function getAllFiles(dir: string): string[] {
153155 return files ;
154156}
155157
158+ /**
159+ * Clean up Angular ngcc lock files from all packages that could interfere with yarn install.
160+ * These lock files can cause ENOENT errors when yarn tries to copy files from file: dependencies.
161+ */
162+ function cleanupNgccLockFiles ( ) : void {
163+ const packagesDir = path . resolve ( __dirname , '../..' ) ;
164+ const packageDirs = fs
165+ . readdirSync ( packagesDir , { withFileTypes : true } )
166+ . filter ( dirent => dirent . isDirectory ( ) )
167+ . map ( dirent => dirent . name )
168+ . filter ( name => ! name . startsWith ( '.' ) ) ;
169+
170+ for ( const packageDir of packageDirs ) {
171+ const lockFilePath = path . join ( packagesDir , packageDir , 'node_modules' , '.ngcc_lock_file' ) ;
172+ if ( fs . existsSync ( lockFilePath ) ) {
173+ try {
174+ fs . unlinkSync ( lockFilePath ) ;
175+ console . log ( `Removed ${ lockFilePath } ` ) ;
176+ } catch {
177+ console . warn ( `Warning: Could not remove ${ lockFilePath } ` ) ;
178+ }
179+ }
180+ }
181+ }
182+
156183function buildPackageJson ( ) : void {
157184 console . log ( 'Building package.json' ) ;
158185 const packagesDir = path . resolve ( __dirname , '../..' ) ;
0 commit comments