diff --git a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts index 601de304be04..1ffc346a62bc 100644 --- a/packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts +++ b/packages/angular_devkit/build_angular/src/builders/browser-esbuild/compiler-plugin.ts @@ -132,7 +132,7 @@ const WINDOWS_SEP_REGEXP = new RegExp(`\\${path.win32.sep}`, 'g'); export class SourceFileCache extends Map { readonly modifiedFiles = new Set(); - readonly babelFileCache = new Map(); + readonly babelFileCache = new Map(); invalidate(files: Iterable): void { this.modifiedFiles.clear(); @@ -247,7 +247,7 @@ export function createCompilerPlugin( let previousBuilder: ts.EmitAndSemanticDiagnosticsBuilderProgram | undefined; let previousAngularProgram: NgtscProgram | undefined; - const babelDataCache = new Map(); + const babelDataCache = new Map(); const diagnosticCache = new WeakMap(); build.onStart(async () => { @@ -466,7 +466,8 @@ export function createCompilerPlugin( // would need to be added to the key as well. let contents = babelDataCache.get(data); if (contents === undefined) { - contents = await transformWithBabel(args.path, data, pluginOptions); + const transformedData = await transformWithBabel(args.path, data, pluginOptions); + contents = Buffer.from(transformedData, 'utf-8'); babelDataCache.set(data, contents); } @@ -490,7 +491,8 @@ export function createCompilerPlugin( let contents = pluginOptions.sourceFileCache?.babelFileCache.get(args.path); if (contents === undefined) { const data = await fs.readFile(args.path, 'utf-8'); - contents = await transformWithBabel(args.path, data, pluginOptions); + const transformedData = await transformWithBabel(args.path, data, pluginOptions); + contents = Buffer.from(transformedData, 'utf-8'); pluginOptions.sourceFileCache?.babelFileCache.set(args.path, contents); }