vim-prettier icon indicating copy to clipboard operation
vim-prettier copied to clipboard

Prettier: failed to parse buffer (PrettierAsync) for every JS file

Open ds82 opened this issue 5 years ago • 41 comments

Do you want to request a feature or report a bug? Bug

What is the current/expected behavior? Using PrettierAsync always results in the error Prettier: failed to parse buffer. Prettier command works fine (on every file).

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

What is your prettier executable path - (output of :PrettierCliPath) ? /Users/dsaenger/code/titan-web/node_modules/.bin/prettier (local project path)

Did this work in previous versions of vim-prettier and/or prettier ? Did not use vim-prettier before

To be clear: This error always occurs with whatever JS file when using :PrettierAsync, even Hello World:

console.log('Hello World');

.. but :Prettier works fine.

I'm using https://github.com/skwp/dotfiles vim config .. maybe vim-prettier does not work with another plugin .. how can I debug this?

ds82 avatar Feb 04 '19 07:02 ds82

I will look into this ASAP

mitermayer avatar Feb 06 '19 22:02 mitermayer

Could you try with the prettier 1.0 branch ?

to try with the 1.0 branch please update your .vimrc to from:

Plug 'prettier/vim-prettier', { 'do': 'yarn install' }

to:

Plug 'prettier/vim-prettier', { 'do': 'yarn install', branch: 'release/1.x' }

Curious to see if it still broken in there too

mitermayer avatar Feb 06 '19 22:02 mitermayer

Thanks for taking the time and looking into this! I tried the 1.0 branch but the result is exactly the same :/

ds82 avatar Feb 07 '19 07:02 ds82

HI @ds82 do you mind trying one more thing ?

on your vimrc :

try adding this

let g:prettier#config#config_precedence = 'file-override'

mitermayer avatar Feb 07 '19 23:02 mitermayer

I don't mind at all .. I'm happy that you try to fix my problem! Unfortunately, setting the variable makes no differences either :/

ds82 avatar Feb 08 '19 07:02 ds82

Hi @mitermayer, I had the same problem but switching to the release/1.x branch with 1.0.0-alpha version from the PrettierVersion command fixed the issue for me.

joerter avatar Feb 18 '19 20:02 joerter

I will try to merge release/1.x branch to master ASAP, in the meantime feel free folks to use that branch directly

Plug 'prettier/vim-prettier', {
  \ 'do': 'yarn install',
  \ 'branch': 'release/1.x',
  \ 'for': [
    \ 'javascript',
    \ 'typescript',
    \ 'css',
    \ 'less',
    \ 'scss',
    \ 'json',
    \ 'graphql',
    \ 'markdown',
    \ 'vue',
    \ 'lua',
    \ 'php',
    \ 'python',
    \ 'ruby',
    \ 'html',
    \ 'swift' ] }

mitermayer avatar Feb 18 '19 23:02 mitermayer

If anyone else could please try the release/1.x branch to confirm that it does fix this issue that would be great!

mitermayer avatar Feb 18 '19 23:02 mitermayer

Tried the branch again (hash cb598c1212dfe20f5a5a950bdee529d224d574d9), but still does not work :/

ds82 avatar Feb 21 '19 11:02 ds82

@ds82 thanks for trying, can you post your vim --version paste ? I am still trying to figure out how to repro

mitermayer avatar Feb 21 '19 20:02 mitermayer

I've just got this issue, trying the vim-prettier with release/1.x branch, to get the php support. Both in js and php files running :Prettier and :PrettierAsync resulted in Prettier: failed to parse buffer.

The cause appeared to be the ruby plugin, I've just removed it manually for now:

~/.vim/plugged/vim-prettier on release/1.x!
$ yarn remove @prettier/plugin-ruby

Sidenote: the error message is not informative enough, maybe consider adding some debug / verbose mode. To find the issue I added echo a:errors into this functiona:

function! prettier#job#runner#onError(errors) abort
  call prettier#logging#error#log('PARSING_ERROR')
  echo 'Errors'
  echo a:errors
  ...
endfunction

And got the error:

[
'/home/user/.vim/plugged/vim-prettier/node_modules/@prettier/plugin-ruby/src/nodes.js:5', 
'  ...require("./nodes/alias"),',
'  ^^^',
'SyntaxError: Unexpected token ...',
'    at createScript (vm.js:56:10)',
'    at Object.runInThisContext (vm.js:97:10)',
'    at Module._compile (module.js:542:28)',
'    at Object.Module._extensions..js (module.js:579:10)
',
'    at Module.load (module.js:487:32)',
'    at tryModuleLoad (module.js:446:12)',
'    at Function.Module._load (module.js:438:3)',
'    at Module.require (module.js:497:17)
',
'    at require (internal/module.js:20:19)',
'    at Object.<anonymous> (/home/user/.vim/plugged/vim-prettier/node_modules/@prettier/plugin-ruby/src/print.js:3:15)',
'    at Module._compile (module.js:570:32)',
'    at Object.Module._extensions..js (module.js:579:10)',
'    at Module.load (module.js:487:32)',
'    at tryModuleLoad (module.js:446:12)',
'    at Function.Module._load (module.js:438:3)',
'    at Module.require (module.js:497:17)'
]

serebrov avatar Feb 26 '19 12:02 serebrov

Hi @ serebrov

The above error seems to come from prettier/ruby cc @kddeisz

mitermayer avatar Mar 07 '19 20:03 mitermayer

On the sidenote i will add to release/1.x a task to have errors a bit more clear when they are non syntax related

mitermayer avatar Mar 07 '19 20:03 mitermayer

What's the minimum node version required for this? I specified 8 in the ruby plugin, but maybe I need to support older versions. This is using the spread operator which I guess this doesn't understand.

kddnewton avatar Mar 07 '19 21:03 kddnewton

Hi @kddeisz ,

We currently do not have any specified node version https://github.com/prettier/vim-prettier/blob/master/package.json

mitermayer avatar Mar 08 '19 03:03 mitermayer

Alright I just released v0.8.0 for @prettier/plugin-ruby which supports the obsolete node versions. Let me know if people still have problems.

kddnewton avatar Mar 08 '19 19:03 kddnewton

Thanks @kddeisz !

mitermayer avatar Mar 08 '19 21:03 mitermayer

Just updated release/1.x to have the latest ruby prettier plugin https://github.com/prettier/vim-prettier/commit/18a42315acc254755b122b4afaf3896466227b6c

@serebrov do you mind trying it again ?

mitermayer avatar Mar 08 '19 21:03 mitermayer

@mitermayer yes, works for me now on node 6.10.

serebrov avatar Mar 09 '19 10:03 serebrov

Is this closable? It's just still on my radar so just want to make sure it's all fixed up.

kddnewton avatar Mar 11 '19 13:03 kddnewton

This issue is closed on release/1.x but since master still behind i will leave it open until this weekend when i will do the release/1.x release!

mitermayer avatar Mar 11 '19 16:03 mitermayer

Sounds great!

kddnewton avatar Mar 11 '19 17:03 kddnewton

This issue has been solved on release/1.x branch will close this to help me track fixed issues for the release changelog

mitermayer avatar Sep 14 '19 05:09 mitermayer

This issue is NOT solved in release/1.x

1.0.0 alpha still fails

stiofand avatar Apr 25 '20 12:04 stiofand

Will reopen this to investigate issue reported above

mitermayer avatar Apr 25 '20 22:04 mitermayer

I just ran into this message - sounds slightly different then what others are experiencing, but maybe one of these steps will help somebody else who lands here.

In my case, running :PrettierCliPath in vimh told me where my executables were, and then running that executable directly against any JS file revealed that I had an invalid .prettierrc for the version of prettier which installed with vim-prettier (but not my system version).

/Users/me/.vim/plugged//vim-prettier/node_modules/.bin/prettier myfile.tsx

resulted in

[error] Unable to expand glob patterns: hooks/useMeasure.tsx !**/node_modules/** !./node_modules/** !**/.{git,svn,hg}/** !./.{git,svn,hg}/**
[error] Invalid trailingComma value. Expected "all", "none", "php5" or "php7.2", but received "es5".

From here, fixing was easy, just fix errors in my .prettierrc until it stopped complaining. Now it's working great!

kelly-ry4n avatar May 27 '20 22:05 kelly-ry4n

I had the same issue after updating node to lts (v12.17.0 in my case). I upgraded to newest prettier version (2.0.5) and it works now.

gabrielhpugliese avatar Jun 04 '20 09:06 gabrielhpugliese

I encountered the same issue. on Sep 15, 2020

winkee01 avatar Sep 15 '20 11:09 winkee01

I met same issue, Step 18, 2020 This is my configuration: https://github.com/lioaslan/nvim And I run :Prettier with a simple JS code

const x = 5;
            console.log(x);

It showed that error

khaitranhq avatar Sep 18 '20 11:09 khaitranhq

I had the same issue. All I did just npm i -g prettier, and it works now.

masdarzulfikar avatar Sep 18 '20 22:09 masdarzulfikar