Do you want to request a feature or report a bug?
Bug.
What is the current/expected behavior?
Prettier cannot format the file due to Prettier: failed to parse buffer. This occurs both on save and when executing the :Prettier and PrettierAsync commands manually. The same error occurs on both macvim and neovim.
What version of vim-prettier are you using - (output of :PrettierVersion) ?
0.2.7
What version of prettier are you using - (output of :PrettierCliVersion) ?
1.18.2
What is your prettier executable path - (output of :PrettierCliPath) ?
prettier
Did this work in previous versions of vim-prettier and/or prettier ?
Previously worked on neovim, not working on macvim. However, the last time it was used was months ago and I can't give a specific version that it worked under.
This is off of a clean prettier install. I don't know if it would be due to other plugins but below are the plugins I have enabled:
" Plug
1 call plug#begin('~/.vim/plugged')
2 Plug 'Valloric/YouCompleteMe'
3 Plug 'altercation/vim-colors-solarized'
4 Plug 'scrooloose/nerdtree'
5 Plug 'junegunn/goyo.vim'
6 Plug 'nvie/vim-flake8', {'for': 'python'}
7 Plug 'jiangmiao/auto-pairs', {'for': ['python', 'html', 'css']}
8 Plug 'vimwiki/vimwiki'
9 Plug 'suan/vim-instant-markdown', {'for': 'markdown'}
10 Plug 'mattn/emmet-vim'
11 Plug 'prettier/vim-prettier', {
12 \ 'do': 'yarn install',
13 \ 'branch': 'release/1.x',
14 \ 'for': [
15 \ 'javascript',
16 \ 'typescript',
17 \ 'css',
18 \ 'less',
19 \ 'scss',
20 \ 'json',
21 \ 'graphql',
22 \ 'markdown',
23 \ 'vue',
24 \ 'lua',
25 \ 'php',
26 \ 'python',
27 \ 'ruby',
28 \ 'html',
29 \ 'swift' ] }
30 call plug#end()
I have this same problem. Maybe it's because I updated to a later version. Anyone else getting "failed to parse buffer"?
Same here. It seems to be quite a recurring issue, according to the number of github issues regarding this specific error.
EDIT: Okay, my problem might not be related to this issue in fact. I just have a failed to parse buffer message when my JS has syntax errors.
Stepping back to [email protected] fixed it for me with vim-prettier 0.2.7.
I thought this was weird since the OP reported they were using 1.18.2. So, to make sure it wasn't something unrelated, I double checked by reinstalling 1.19.0. Got the error. Downgraded to 1.18.2. No more error.
For what it's worth, I'm also seeing issues with prettier version 1.19.0 but downgrading to 1.18.x makes everything work fine again.
function Foo(arg: any){
console.log(arg as string)
}
failed to handle type conversion "arg as string" for tsx (vim prints filetype as typescriptreact)
but, cli works just fine.
I am almost on holidays from work, and will look at this issues from tomorrow :)
For what it's worth, I am having the same problem. It seems to be related to the file type.
I tried switching from leafgarland/typescript-vim and peitalin/vim-jsx-typescript to sheerun/vim-polyglot, and vim-prettier fails with the line "failed to parse buffer".
With the two previous plugins the filetype was typescript.tsx and everything worked, now it is typescriptreact and fails. For now I solved this by putting au! BufNewFile,BufRead *.tsx setf typescript.tsx into my filetype.vim. The filetype seems to get overwritten by some plugin, but it still works.
Hi @koljakube,
Great finding, this explain a lot. I previously had removed the filetypes definition from the release/1.x branch due to relying on prettier itself to be capable of identifying the filetype based on extension.
I will re-add that back and dig on upstream to understand what can be going wrong within the communication between vim-prettier and prettier itself
I have reincluded file type definitions and branch 1.0 has been merged into master. Is anyone still facing this issues ?
Please comment/reopen this issue if you are still facing this issue
Still encountering this issue.
Neovim: 0.4.3
Prettier Version: 1.0.0-alpha
Prettier CLI version: 1.19.1
Prettier CLI Path: /home/krog/.vim/plugged/vim-prettier/node_modules/.bin/prettier
Node version: 11.15.0
I've tried removing and reinstalling prettier and it has worked with previous versions. Just downgraded to 0.9x branch and have had no issues.
Plugins:
call plug#begin("~/.vim/plugged")
" Colorscheme
Plug 'flazz/vim-colorschemes'
Plug 'dracula/vim'
Plug 'drewtempelmeyer/palenight.vim'
"Tpope plugins
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-ragtag'
"Javascript / React
Plug 'pangloss/vim-javascript'
Plug 'elzr/vim-json'
Plug 'maxmellon/vim-jsx-pretty'
Plug 'jxnblk/vim-mdx-js'
"ruby / rails
Plug 'vim-ruby/vim-ruby'
Plug 'ngmy/vim-rubocop'
Plug 'tpope/vim-rails'
Plug 'tpope/vim-bundler'
"html / css
Plug 'mattn/emmet-vim'
Plug 'ap/vim-css-color'
Plug 'prettier/vim-prettier', {
\ 'do': 'yarn install',
\ 'branch': 'release/0.x'
\ }
"Markdown previewing, Ensure you have nodejs and yarn
Plug 'iamcco/markdown-preview.nvim', { 'do': 'cd app & yarn install' }
" Snippets
Plug 'SirVer/ultisnips'
" Linting
Plug 'dense-analysis/ale'
" Autocompletion
Plug 'neoclide/coc.nvim', {'branch': 'release'}
" CoC recommended config
let g:coc_start_at_startup = 1
let g:coc_global_extensions = [
\ 'coc-json',
\ 'coc-css',
\ 'coc-ultisnips',
\ 'coc-tsserver',
\ 'coc-emmet',
\ 'coc-tag',
\ 'coc-omni',
\ 'coc-syntax',
\ 'coc-yaml',
\ 'coc-solargraph',
\ 'coc-phpls',
\ 'coc-html',
\ 'coc-tailwindcss',
\ 'coc-markdownlint',
\ 'coc-git'
\ ]
call plug#end()
Thanks for including your config it is super helpful , I will investigate this issue with neovim and comment in here
Let me know if there's any other way I can help. My full config is here:
https://github.com/ParamagicDev/config-files/blob/master/dotfiles/vimrc
I haven't tested whether it works in regular vim yet. I'll test it next time I'm at my computer. I'll also try removing plugins 1 by 1. Who knows, it could be a plug-in compatibility issues.
So I found that the issue comes up specifically in this repository when editing .js files. More specifically, the .js files in the src/components/ directory.
https://github.com/ParamagicDev/ma-protocol-rewrite/tree/development
I've tried changing the default parser to Babylon and that did not fix the issue. I swapped over into one of my rails projects and did not encounter the issue with .js files.
My best guess is that .prettierrc Or the .eslintrc.js file provided by Gatsby may be causing the error. I'm not 100% however.
EDIT:
I removed my .prettierrc file from the repo and the issue no longer occurred.
The issue is definitely with my .prettierrc file.
The issue only occurs with 1.0.0-alpha.
The issue does not occur with the '0.x' branch.
The issue occurs both when I use neovim and regular vim.
The issue resolves when I remove .prettierrc.
The issue does not occur when using command line prettier.
hi @ParamagicDev
Thank you for the snippet, I am able to reproduce this issue on my end!
This bug seems to be something related to the .prettierrc in that repo, if i delete that file the vim-prettier works as expected.
Will keep digging into it and comment in here any findings
@ParamagicDev
It looks like the problem is that one of vim-prettier dependencies is bringing a broken version of prettier CLI, managed to fix this by updating the yarn lock file.
can you please try the following and see if you can still repro this error:
node_modules from ~/.vim/plugged/vim-prettieryarn installWith the above i was no longer able to repro that issue
@mitermayer Thank you so much for this. Everything's working as expected now.
Closing this issue now, feel free to comment or reopen this issue if anyone experience same problem again
I'm still having issues with this. If I remove my .prettierrc.json file it works. It appears I have the commit posted above in my yarn.lock file. Any suggestions?
@nratter Perhaps a syntax error with your .prettierrc.json? I can confirm the solution fixed my original problem but a syntax error with configuring Prettier caused it to reappear, fixed by re-examining the file.
@kyle-dormer There were no syntax errors in my .prettierrc.json file. However, I was able to fix this by using 'branch': 'release/0.x' in the vim-plug options.
I can confirm that this bug is still live on the latest version of vim-prettier. The solution for me was to install both leafgarland/typescript-vim and peitalin/vim-jsx-typescript. This changed the filetype from typescriptreact to typescript.tsx
I don't know why this PR is closed, its very frustrating having this bug with the actual release ! what @mitermayer proposed solved my problem but I've lost some time ..
Further, I have no determined that normal typescript files (:set filetype? returns typescript) do not trigger prettier on save either. I had to add the following workaround to my vimrc:
autocmd BufRead,BufNewFile *.ts set filetype=typescript.tsx
I also have this bug, newest vim-prettier. for some reason, when I switched to using prettier through coc-prettier instead of vim-prettier, everything worked just fine
Same here. I think this issue should be reopened.
Reverting back to 'release/1.x' branch also works, and that's the solution I'm sticking with.
For future folks who discover this issue, I ended up switching to ale + prettier instead and it's working flawlessly. Once you install Ale (I did it via Plug), you just add this to your .vimrc
let g:ale_fix_on_save = 1
let g:ale_fixers = {
\ 'javascript': ['prettier', 'eslint'],
\ 'typescript': ['prettier', 'eslint'],
\}
I still have this issue when I try to format manually with :Prettier
Most helpful comment
I am almost on holidays from work, and will look at this issues from tomorrow :)