Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier code format take a long time to format #2999

Open
ggx-roynguyen opened this issue Apr 27, 2023 · 54 comments
Open

Prettier code format take a long time to format #2999

ggx-roynguyen opened this issue Apr 27, 2023 · 54 comments

Comments

@ggx-roynguyen
Copy link

ggx-roynguyen commented Apr 27, 2023

Type: Bug

I dont know why but my prettier take about 1-2s to format.
image

Extension version: 9.12.0
VS Code version: Code 1.77.3 (Universal) (704ed70d4fd1c6bd6342c436f1ede30d1cff4710, 2023-04-12T09:19:37.325Z)
OS version: Darwin arm64 21.4.0
Modes:
Sandboxed: Yes

System Info
Item Value
CPUs Apple M1 Pro (8 x 24)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_renderer: enabled_on
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off
Load (avg) 5, 5, 4
Memory (System) 16.00GB (1.41GB free)
Process Argv --crash-reporter-id b70f3c63-e04c-4015-8b63-1803fe3fdfa6
Screen Reader no
VM 0%
A/B Experiments
vsliv368:30146709
vsreu685:30147344
python383cf:30185419
vspor879:30202332
vspor708:30202333
vspor363:30204092
vslsvsres303:30308271
vserr242:30382549
pythontb:30283811
vsjup518:30340749
pythonptprofiler:30281270
vshan820:30294714
vstes263cf:30335440
vscoreces:30445986
pythondataviewer:30285071
vscod805cf:30301675
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
cmake_vspar411:30581797
vsaa593:30376534
pythonvs932:30410667
cppdebug:30492333
vsclangdc:30486549
c4g48928:30535728
dsvsc012:30540252
pynewext54:30695312
azure-dev_surveyone:30548225
vsccc:30610678
nodejswelcome1cf:30587006
3biah626:30602489
pyind779:30671433
f6dab269:30613381
pythonsymbol12:30671437
a9j8j154:30646983
vsctsb:30705553
azdwalk:30721579
pythonms35:30701012
pythonfmttextcf:30716743

@irlTopper
Copy link

Same. If I use "developer: reload windows", it's perfect again for a little while. But 20 seconds later, saving is slow again.

@Sisableng
Copy link

idk, I can't share the results, but I just waited for this for over 30 minutes.
i have 16GB of Memory, available 9GB

i tried to disable other extensions, but still slow even i just enable prettier plugin,
i hope dev, have solution of this problem

Screenshot (1)

@Sisableng
Copy link

finnaly this is the output

Screenshot (2)

@roguesherlock
Copy link

I thought I was the only one but I think the recent version is causing the same issues for me

@ameer-taghavi
Copy link

same issue for me after updated macOS to 13.3 and updated vs code to the last version

@z-verse
Copy link

z-verse commented May 2, 2023

same issue, after updating plugin to 9.12.
macOS 13.2.1, VS Code 1.77.3

@beeb
Copy link

beeb commented May 3, 2023

Same problem here. Windows 11, using WSL2, and macOS 13.2.1. Latest VSCode

Debug logs don't show errors:

["INFO" - 3:10:57 PM] Formatting file:///home/valentin/[redacted]/src/components/[redacted].astro
["INFO" - 3:10:58 PM] Using config file at '/home/valentin/[redacted]/.prettierrc'
["DEBUG" - 3:10:58 PM] Local prettier module path: '/home/valentin/[redacted]/node_modules/prettier/index.js'
["INFO" - 3:10:58 PM] Using ignore file (if present) at /home/valentin/[redacted]/.prettierignore
["INFO" - 3:10:58 PM] File Info:
{
  "ignored": false,
  "inferredParser": "astro"
}
["INFO" - 3:10:58 PM] Detected local configuration (i.e. .prettierrc or .editorconfig), VS Code configuration will not be used
["INFO" - 3:10:58 PM] Prettier Options:
{
  "filepath": "/home/valentin/[redacted].astro",
  "parser": "astro",
  "useTabs": true,
  "singleQuote": true,
  "trailingComma": "none",
  "printWidth": 120,
  "pluginSearchDirs": [
    "/home/valentin/[redacted]"
  ],
  "semi": false
}
["INFO" - 3:10:58 PM] Formatting completed in 1326ms.

The first line in the logs takes a long time to arrive after hitting the save button.

Sometimes, there is a long waiting time after the first line, and then the extension crashes.

image

A little bissect shows prettier is the culprit:

image

@timmeade
Copy link

timmeade commented May 3, 2023

Same issue here. Mac. i went back one version and it worked great for 1 day now is back slow. just verified still back one version.

This is a MUST fix.

@timmeade
Copy link

timmeade commented May 3, 2023

Same issue here. Mac. i went back one version and it worked great for 1 day now is back slow. just verified still back one version.

This is a MUST fix.

I just set the Default Formatter for the Workspace to prettier. I had it set for the user but the workspace was still unset. It seems to be working again.

TLDR Set the default formatter in BOTH workspace and user settings.

UPDATE: It's back .... Going to have to uninstall this.

@ameer-taghavi
Copy link

ameer-taghavi commented May 6, 2023

Screenshot 1402-02-16 at 10 37 50

I unchecked these options and the problem was solved for me!
@t0rbik
Copy link

t0rbik commented May 7, 2023

Same issue.

@aokigit
Copy link

aokigit commented May 9, 2023

Same issue here. I'm 🤏 this close to uninstalling cause it's unbearable.

@kristinabrueva
Copy link

kristinabrueva commented May 10, 2023

I got this problem right after adding Jest tests to my NextJs project. Before that it was running and saving files with no issues. Now, the Prettier runs forever and I can't safe my changes unless I press cancel.
I had the same problem on a few other projects but this time I noticed that it might be related to tests.
Please help!
Screen Shot 2023-05-10 at 16 28 47

@beeb
Copy link

beeb commented May 10, 2023

I unchecked these options and the problem was solved for me!

@ameer-taghavi doesn't work for me. Still having the issue with those settings disabled.

@mrroll
Copy link

mrroll commented May 11, 2023

Reverting to v9.10.4 appears to be working for me.

Edit No it does not.

@Terit
Copy link

Terit commented May 11, 2023

After trying many of the possible fixes listed in this thread and others in this repo I still ran into this issue. Even after disabling the Prettier extension I ran into the same issues with VS Code's TypeScript formatter.

Eventually I found an issue in the VS Code repo which reported the same issues. I'm happy to report after downgrading to version 1.76.2 and using VS Code heavily for the past 2 days I'm not longer seeing issues with Prettier formatting taking forever to load.

Instructions on how to downgrade and prevent automatic updates from wiping out those changes can be found here.

@osilkin98
Copy link

Is there an ETA on when this will be fixed? This is a pretty breaking bug that I'm surprised doesn't have a higher visibility

@lawrence-cruz
Copy link

If you are using Auto Import - ES6, TS, JSX, TSX extension, try to uninstall it and replace it with Auto Import.

image
image

#1333 (comment)

@cptSwing
Copy link

After trying many of the possible fixes listed in this thread and others in this repo I still ran into this issue. Even after disabling the Prettier extension I ran into the same issues with VS Code's TypeScript formatter.

Eventually I found an issue in the VS Code repo which reported the same issues. I'm happy to report after downgrading to version 1.76.2 and using VS Code heavily for the past 2 days I'm not longer seeing issues with Prettier formatting taking forever to load.

Instructions on how to downgrade and prevent automatic updates from wiping out those changes can be found here.

For now, this is what worked for me as well!

@WagnerMoreira
Copy link

After trying many of the possible fixes listed in this thread and others in this repo I still ran into this issue. Even after disabling the Prettier extension I ran into the same issues with VS Code's TypeScript formatter.

Eventually I found an issue in the VS Code repo which reported the same issues. I'm happy to report after downgrading to version 1.76.2 and using VS Code heavily for the past 2 days I'm not longer seeing issues with Prettier formatting taking forever to load.

Instructions on how to downgrade and prevent automatic updates from wiping out those changes can be found here.

This worked for me 👍

@psd-coder
Copy link

The same issue. I do not have installed Auth import plugin. The problem appeared when I updated VS Code to the version above 1.76.2. Fixing VS Code version on 1.76.2 fixes the problem.

@hasokeric
Copy link

I am facing the same issue, I am on the Insiders build even.

@timmeade
Copy link

timmeade commented Jun 3, 2023

I never found it after looking and trying things for days. i have since went back to 1.76.2 per @WagnerMoreira above and have not had the issue since. Just waiting on someone to say they found the root cause before upgrading.

@maccman
Copy link

maccman commented Jun 4, 2023

Running into this issue as well. :(

@hasokeric
Copy link

I downgraded to 1.76 and the issues went away.

@sdsoldi
Copy link

sdsoldi commented Jun 7, 2023

So? The "fix" is downgrade to 1.76?

@omer-bar
Copy link

omer-bar commented Jun 7, 2023

So? The "fix" is downgrade to 1.76?

Didnt work for me, i just use Rome for now...
tried all the solutions i could find, still waiting 13-40 seconds for a file to save... if i do 2 saves or cancel the save then it pushes the changes and saves the file without the formatting and sometimes a third save after that is a quick 13ms~ save.
so either CTRL+S twice or cancel the save and save again or use something else like Rome.

@hasokeric
Copy link

Is this the related issue, finally someone caught it? We should be able to see if it solves it in the next minor releases, perhaps insiders... microsoft/vscode#184926

@Sisableng
Copy link

in my case, the problem is prettier-plugin-tailwindcss, i try remove this package, idk but all back to normal without automatically sorting class

@caioq
Copy link

caioq commented Jun 29, 2023

This was the solution for me: #3044 (comment)

@Soviut
Copy link

Soviut commented Jul 20, 2023

VSCode 1.80.x which includes the fix for microsoft/vscode#184926 just dropped and seems to have solved the issues.

@mpearce-bain
Copy link

VSCode 1.80.x which includes the fix for microsoft/vscode#184926 just dropped and seems to have solved the issues.

Unfortunately the latest version still hasn't resolved the issue for me 😢

@Soviut
Copy link

Soviut commented Jul 21, 2023

@mpearce-bain Double check that you are on the latest version of VSCode (1.80.1 as if this date). Similarly, make sure the prettier extension is up to date, prettier for tailwind is up to date, etc. If it's still going slowly, try disabling extensions that contribute to formatting.

@dmt0
Copy link

dmt0 commented Jul 21, 2023

I'm on 1.80.1. All extensions up to date. On large files (2K lines or so) prettier still takes several seconds (15" macbook with i9 CPU, 32GB RAM). I do have a lot of extensions enabled, and I'm sure if I go through all of them I'll find a culprit. I'd assume though that a proper fix implies that I don't have to disable extensions.

Side note: rome works fine, but I don't feel that it's very stable feature-wise - even the formatter part. I'd wait a couple more major version before doing a switch.

@dmt0
Copy link

dmt0 commented Jul 28, 2023

Found the offending extension. In my case it's Glean.
wix-incubator/vscode-glean#157
Once disabled I actually got a performance boost, for all kinds of operations, not just formatting. So perhaps in my case prettier was not a problem at all. 🤷‍♂️

@DeedeeSRB
Copy link

DeedeeSRB commented Aug 24, 2023

For me the fix was to disable the Console Ninja extension. After I disabled and enabled it again, everything seemed to be working just fine.

@flexchar
Copy link

After trying many of the possible fixes listed in this thread and others in this repo I still ran into this issue. Even after disabling the Prettier extension I ran into the same issues with VS Code's TypeScript formatter.

Eventually I found an issue in the VS Code repo which reported the same issues. I'm happy to report after downgrading to version 1.76.2 and using VS Code heavily for the past 2 days I'm not longer seeing issues with Prettier formatting taking forever to load.

Instructions on how to downgrade and prevent automatic updates from wiping out those changes can be found here.

Recently tried upgrading to the latest VS Code as of October, 2023. The issue came back creeping from behind with zero hesitation. There must have been some fundamental change in the program. Using Prettier 3 btw.

@BVBFD
Copy link

BVBFD commented Nov 11, 2023

extention_bisect

Using extension bisect get me realize that "Auto Import" extension conflicts with prettier in big sized coding file.
So, I recommend others having this issue try to use extension bisect in order to get to know which one is problem.

@liuJchun
Copy link

it work for me, see this issue
#3044

@arjunghimire
Copy link

If you are using Auto Import - ES6, TS, JSX, TSX extension, try to uninstall it and replace it with Auto Import.

image image

#1333 (comment)

This is working for me. Great thanks you safe my life bro

@bouncingbumble
Copy link

#3044 (comment)

thank god, this worked for me

@dpw1
Copy link

dpw1 commented Dec 28, 2023

In my case the extension "Live Sass Compiler" was the cause of Prettier's slowness. It seems that almost always the reason comes from a conflict from another extension, so I'd suggest disabling them to test it out before installing an older version

Copy link

This issue has been labeled as stale due to inactivity. Reply to keep this issue open.

@github-actions github-actions bot added the Stale label Feb 27, 2024
@flexchar
Copy link

flexchar commented Feb 27, 2024 via email

@github-actions github-actions bot removed the Stale label Feb 28, 2024
@TenviLi
Copy link

TenviLi commented Mar 11, 2024

If you are using Auto Import - ES6, TS, JSX, TSX extension, try to uninstall it and replace it with Auto Import.

image image

#1333 (comment)

Thank you for your solution.

@TenviLi
Copy link

TenviLi commented Mar 15, 2024

I've been experiencing an issue where FormatOnSave causes lag and Git becomes unresponsive. I'm running on Windows with the Auto Import extension installed. Disabling Prettier and Auto Import didn't resolve this.

Interestingly, opening a super-long file ignored by .gitignore seems to crash the VSCode Extension Host.

However, since switching to the Windows Subsystem for Linux (WSL), everything has been operating smoothly.

@NH-Shohan
Copy link

If you are using Auto Import - ES6, TS, JSX, TSX extension, try to uninstall it and replace it with Auto Import.

image image

#1333 (comment)

This worked for me. I had the same issue. Thank you!

@leandroruel
Copy link

prettier is literally killing my WSL2 everytime i format onsave =/

@ShahramShakiba
Copy link

If you use "Prettier ESLint" try to disable it and only use "Prettier - Code formatter". This is how I fix mine

@leandroruel
Copy link

for those facing it with WSL2 what helped me was to increase the amount of RAM to WSL2, just create .wslconfig file in your user folder eg: C:\Users\[YourUserName]:

# Settings apply across all Linux distros running on WSL 2
[wsl2]

# Limits VM memory to use no more than 4 GB, this can be set as whole numbers using GB or MB
memory=4GB 

# Sets the VM to use two virtual processors
processors=2

# Specify a custom Linux kernel to use with your installed distros. The default kernel used can be found at https://github.com/microsoft/WSL2-Linux-Kernel
#kernel=C:\\temp\\myCustomKernel

# Sets additional kernel parameters, in this case enabling older Linux base images such as Centos 6
#kernelCommandLine = vsyscall=emulate

# Sets amount of swap storage space to 8GB, default is 25% of available RAM
swap=8GB

# Sets swapfile path location, default is %USERPROFILE%\AppData\Local\Temp\swap.vhdx
swapfile=C:\\temp\\wsl-swap.vhdx

# Disable page reporting so WSL retains all allocated memory claimed from Windows and releases none back when free
pageReporting=false

# Turn on default connection to bind WSL 2 localhost to Windows localhost. Setting is ignored when networkingMode=mirrored
localhostforwarding=true

# Disables nested virtualization
nestedVirtualization=false

# Turns on output console showing contents of dmesg when opening a WSL 2 distro for debugging
debugConsole=true

# Enable experimental features
[experimental]
sparseVhd=true
@gorn
Copy link

gorn commented May 29, 2024

I am having this issue and is really annoying to the point that VSCode is unusable (without automatic formatting).

@DhanushkaNP
Copy link

If you are using Auto Import - ES6, TS, JSX, TSX extension, try to uninstall it and replace it with Auto Import.

image image

#1333 (comment)

This worked for me. Bought a new memory thinking that this was related to a memory issue😅

@Silon
Copy link

Silon commented Jul 15, 2024

In my case problem was caused by wrong tailwindcss configuration but most helpful thing can be the way I discovered it.
Prettier plugin console didn't show any error but I ran Prettier formatting via cli (prettier --write "**/*.{ts,tsx,md}") and I found importing error in tailwind file. After fix Prettier works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment