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

Bug: failed to parse buffer. #214

Closed
kdormer opened this issue Oct 26, 2019 · 33 comments
Closed

Bug: failed to parse buffer. #214

kdormer opened this issue Oct 26, 2019 · 33 comments

Comments

@kdormer
Copy link

kdormer commented Oct 26, 2019

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()
@geoyws
Copy link

geoyws commented Oct 28, 2019

I have this same problem. Maybe it's because I updated to a later version. Anyone else getting "failed to parse buffer"?

@t-mdo
Copy link

t-mdo commented Nov 2, 2019

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.

@markplindsay
Copy link

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.

@daern91
Copy link

daern91 commented Dec 16, 2019

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.

@aca
Copy link

aca commented Dec 23, 2019

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.

@mitermayer
Copy link
Member

mitermayer commented Dec 23, 2019

I am almost on holidays from work, and will look at this issues from tomorrow :)

@koljakube
Copy link

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.

@mitermayer
Copy link
Member

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

@mitermayer
Copy link
Member

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

@KonnorRogers
Copy link
Contributor

KonnorRogers commented Feb 15, 2020

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()

@mitermayer
Copy link
Member

Thanks for including your config it is super helpful , I will investigate this issue with neovim and comment in here

@mitermayer mitermayer reopened this Feb 16, 2020
@KonnorRogers
Copy link
Contributor

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.

@KonnorRogers
Copy link
Contributor

KonnorRogers commented Feb 18, 2020

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.

Link to 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.

@mitermayer
Copy link
Member

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

@mitermayer
Copy link
Member

mitermayer commented Feb 18, 2020

@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:

  1. update vim-prettier to latest master (should contain this commit 7041b9c)
  2. delete the existing node_modules from ~/.vim/plugged/vim-prettier
  3. do a yarn install

With the above i was no longer able to repro that issue

@KonnorRogers
Copy link
Contributor

@mitermayer Thank you so much for this. Everything's working as expected now.

@mitermayer
Copy link
Member

Closing this issue now, feel free to comment or reopen this issue if anyone experience same problem again

@nratter
Copy link

nratter commented Jun 30, 2020

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?

@kdormer
Copy link
Author

kdormer commented Jul 2, 2020

@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.

@nratter
Copy link

nratter commented Jul 2, 2020

@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.

@theycallmeswift
Copy link

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

@ItsTarik
Copy link

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 ..

@theycallmeswift
Copy link

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

@stumash
Copy link

stumash commented Oct 21, 2020

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

@PROgram52bc
Copy link

Same here. I think this issue should be reopened.
#171 mentions something similar to this line, according to which, installing prettier globally seems to fix the issue, but there is not a satisfactory description on where the problem is.
Reverting back to 'release/1.x' branch also works, and that's the solution I'm sticking with.

@theycallmeswift
Copy link

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'],
  \}

@marcmarina
Copy link

I still have this issue when I try to format manually with :Prettier

@jikkujose
Copy link

jikkujose commented Nov 29, 2021

I am still having this issue! Interestingly its not there for typescript files!

Also, :PrettierCli gives this: [error] No parser and no file path given, couldn't infer a parser.^@

@nippyin
Copy link

nippyin commented Jul 14, 2022

Me too still have issue and in my case json files are able to format just fine its Yaml file which gives this error Prettier: Failed to parse buffer (PrettierAsync)

@mattxyzeth
Copy link

I was having this issue as well. My prettier config was formatted as JS using module.exports. I converted it to JSON and removed the file extension, and this seemed to have fixed the issue for me. The file name should be .prettierrc, and the format should be JSON.

@kevinw
Copy link

kevinw commented Sep 1, 2022

Also seeing this issue with a fresh install and running :Prettier

@gosukiwi
Copy link

gosukiwi commented Sep 16, 2022

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 was already using ALE, and that works great! Eslint is a bit slow but just leaving prettier is what I wanted anyways :) Thanks @theycallmeswift !

@ts213
Copy link

ts213 commented Jan 22, 2023

Was getting this error for files without an extension. Dissapeared after adding .js extention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests