Vetur: Incompatible with Prettier 2.0 because of parser option babylon which has been removed (replaced by babel)

Created on 23 Mar 2020  路  8Comments  路  Source: vuejs/vetur

  • [x] I have searched through existing issues
  • [x] I have read through docs
  • [x] I have read FAQ

Info

  • Platform: Win
  • Vetur version: 0.24.0
  • VS Code version:

Problem

The parser option babylon has been removed in Prettier 2.0

Error message:

Prettier format failed
[Error - 10:52:04 p.m.] Couldn't resolve parser "babylon"

The fix: https://github.com/vuejs/vetur/blob/master/server/src/modes/script/javascript.ts#L484
Replace babylon with babel

Reproducible Case

Format a Vue File using prettier 2.0

bug prettier

Most helpful comment

@rnenjoy
This is the setting I have in my .vscode/settings.json

{
  "[vue]": {
    // Vetur uses an old version of prettier
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

This is specific enough that it doesn't mess with my other formatting options and fixes the problem with vue files.

All 8 comments

I'm also using prettier 2.0 and am having troubles when this plugin undoes the formatting in the git repo.
At the moment I just told vscode to give preference to the prettier-vscode plugin when formatting.

Anyone news?

@rnenjoy
This is the setting I have in my .vscode/settings.json

{
  "[vue]": {
    // Vetur uses an old version of prettier
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

This is specific enough that it doesn't mess with my other formatting options and fixes the problem with vue files.

@rnenjoy
This is the setting I have in my .vscode/settings.json

{
  "[vue]": {
    // Vetur uses an old version of prettier
    "editor.defaultFormatter": "esbenp.prettier-vscode"
  }
}

This is specific enough that it doesn't mess with my other formatting options and fixes the problem with vue files.

Not an option for me since that affects the whole .vue file and I don't use prettier to format my template, only the script tag.

For now i went into the extension code, and changed babylon to babel manually. Tell me if you guys need help which file to edit.

@rnenjoy how do you do that?

@rnenjoy how do you do that?

Sorry for the delay:
Goto %USERPROFILE%.vscode\extensions\octref.vetur-0.24.0\server\dist\modes\script\javascript.js

Change 398
const parser = scriptDoc.languageId === 'javascript' ? 'babylon' : 'typescript';
to
const parser = scriptDoc.languageId === 'javascript' ? 'babel' : 'typescript';

@rnenjoy just add this line to your .vscode/settings.json file "vetur.format.defaultFormatter.html": "none" it should help you.

Was this page helpful?
0 / 5 - 0 ratings