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?
I will look into this ASAP
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
Thanks for taking the time and looking into this!
I tried the 1.0 branch but the result is exactly the same :/
HI @ds82 do you mind trying one more thing ?
on your vimrc :
try adding this
let g:prettier#config#config_precedence = 'file-override'
I don't mind at all .. I'm happy that you try to fix my problem!
Unfortunately, setting the variable makes no differences either :/
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.
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' ] }
If anyone else could please try the release/1.x branch to confirm that it does fix this issue that would be great!
Tried the branch again (hash cb598c1212dfe20f5a5a950bdee529d224d574d9), but still does not work :/
@ds82 thanks for trying, can you post your vim --version paste ? I am still trying to figure out how to repro
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)'
]
Hi @ serebrov
The above error seems to come from prettier/ruby cc @kddeisz
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
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.
Hi @kddeisz ,
We currently do not have any specified node version https://github.com/prettier/vim-prettier/blob/master/package.json
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.
Thanks @kddeisz !
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 yes, works for me now on node 6.10.
Is this closable? It's just still on my radar so just want to make sure it's all fixed up.
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!
Sounds great!
This issue has been solved on release/1.x branch will close this to help me track fixed issues for the release changelog
This issue is NOT solved in release/1.x
1.0.0 alpha still fails
Will reopen this to investigate issue reported above
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!
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.
I encountered the same issue. on Sep 15, 2020
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
I had the same issue. All I did just npm i -g prettier, and it works now.
I had the same issue. All I did just
npm i -g prettier, and it works now.
It worked for me. Thanks
I had the same issue. All I did just
npm i -g prettier, and it works now.
Thanks! It worked for me, too. I wonder why the local version of prettier doesn't work, though. Is that a bug?
For me, it apparently turned out to be something wrong with the system-installed version of nodejs (which I've never touched because nvm). Installed the LTS from nodejs.org and vim-prettier started working.
npm i -g prettier
This also worked for me.
I've tried all of the above to no fail.
:disappointed:
" Set prettier to run automatically
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.sass,*.json,*.graphql,*.md,*.vue,*.yml, *.yaml, *.html PrettierAsync
let g:prettier#autoformat = 1
let g:prettier#exec_cmd_async = 1
let g:prettier#config#parser = 'babylon'
let g:prettier#config#single_quote = 'true'
let g:prettier#config#trailing_comma = 'all'
Even tried the npm i -g prettier - still failed
Prettier Version: 1.0.0-beta
Prettier CLI Version: 2.2.1
Not sure what to do anymore
I've tried all of the above to no fail.
" Set prettier to run automatically autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.sass,*.json,*.graphql,*.md,*.vue,*.yml, *.yaml, *.html PrettierAsync let g:prettier#autoformat = 1 let g:prettier#exec_cmd_async = 1 let g:prettier#config#parser = 'babylon' let g:prettier#config#single_quote = 'true' let g:prettier#config#trailing_comma = 'all'Even tried the
npm i -g prettier- still failedPrettier Version: 1.0.0-beta
Prettier CLI Version: 2.2.1Not sure what to do anymore
For me, switching to 'release/1.x' branch worked. You might also try out ale, though I haven't tested it.
I had this issue, :Prettier was working as expected but when I was using it on save it failed. I was using this configuration to auto format on save:
let g:prettier#autoformat = 1
let g:prettier#autoformat_require_pragma = 0
Then reading :h prettier I realized that this was outdated, and changed it to:
let g:prettier#autoformat = 0
autocmd BufWritePre *.js Prettier
Now it works. Something to note is that if I use PrettierAsync instead of Prettier on BufWritePre the issue persists. Another thing that may help is that I used yarn instead of npm when installing release/1.x. Plug 'prettier/vim-prettier', { 'do': 'yarn install', 'branch': 'release/1.x' }
I had this issue,
:Prettierwas working as expected but when I was using it on save it failed. I was using this configuration to auto format on save:let g:prettier#autoformat = 1 let g:prettier#autoformat_require_pragma = 0Then reading
:h prettierI realized that this was outdated, and changed it to:let g:prettier#autoformat = 0 autocmd BufWritePre *.js PrettierNow it works. Something to note is that if I use PrettierAsync instead of Prettier on BufWritePre the issue persists. Another thing that may help is that I used yarn instead of npm when installing release/1.x.
Plug 'prettier/vim-prettier', { 'do': 'yarn install', 'branch': 'release/1.x' }
This worked for me even without going to 'release/1.x'
Seems the commands are outdated.
Thanks @andrescuco
This happened to me when i added a new rule to the prettier config that had invalid syntax e.g. "arrowParens", "avoid", instead of "arrowParens": "avoid",
In my case, this is due to the node version in the session that you run vim with is not compatible with prettier that installed locally for the project.
try
./node_modules/.bin/prettier -v
if this errors out, try to lower the node version to around v10.*
in my case,
nvm use v10
got my problem solved.
Most helpful comment
I had the same issue. All I did just
npm i -g prettier, and it works now.