diff --git a/packages/devkit/src/generators/format-files.ts b/packages/devkit/src/generators/format-files.ts index f4c32d826195d..55b0fd642d933 100644 --- a/packages/devkit/src/generators/format-files.ts +++ b/packages/devkit/src/generators/format-files.ts @@ -55,7 +55,10 @@ export async function formatFiles(tree: Tree): Promise { tree.write( file.path, - prettier.format(file.content.toString('utf-8'), options) + // In prettier v3 the format result is a promise + await (prettier.format(file.content.toString('utf-8'), options) as + | Promise + | string) ); } catch (e) { console.warn(`Could not format ${file.path}. Error: "${e.message}"`); diff --git a/packages/nx/src/generators/internal-utils/format-changed-files-with-prettier-if-available.ts b/packages/nx/src/generators/internal-utils/format-changed-files-with-prettier-if-available.ts index 53e0013be524b..3914ec1588786 100644 --- a/packages/nx/src/generators/internal-utils/format-changed-files-with-prettier-if-available.ts +++ b/packages/nx/src/generators/internal-utils/format-changed-files-with-prettier-if-available.ts @@ -45,7 +45,10 @@ export async function formatChangedFilesWithPrettierIfAvailable( tree.write( file.path, - prettier.format(file.content.toString('utf-8'), options) + // In prettier v3 the format result is a promise + await (prettier.format(file.content.toString('utf-8'), options) as + | Promise + | string) ); } catch (e) { console.warn(`Could not format ${file.path}. Error: "${e.message}"`); diff --git a/packages/workspace/src/utils/rules/format-files.ts b/packages/workspace/src/utils/rules/format-files.ts index 2304b3b73a466..cac8cf4401700 100644 --- a/packages/workspace/src/utils/rules/format-files.ts +++ b/packages/workspace/src/utils/rules/format-files.ts @@ -63,7 +63,13 @@ export function formatFiles( } try { - host.overwrite(file.path, prettier.format(file.content, options)); + host.overwrite( + file.path, + // In prettier v3 the format result is a promise + await (prettier.format(file.content, options) as + | Promise + | string) + ); } catch (e) { context.logger.warn( `Could not format ${file.path} because ${e.message}`