Vetur: File not format

Created on 4 Jul 2018  路  8Comments  路  Source: vuejs/vetur

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

Info

  • Platform: Windows
  • Vetur version: 0.12.5
  • VS Code version: 1.24.1

Problem

The .vue file is not formated.
I have this code :

<template>
    <h1>Hello World</h1>
</template>

<script>
import seo from  "~/plugins/seo"

export default {
  head() {
    return {
      title: "Accueil",
      meta: [
        ...seo.title("Accueil")
      ]
    }
  }
}
</script>

And my eslint :

module.exports = {
  root: true,
  env: {
    browser: true,
    node: true
  },
  extends: [
    // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
    // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
    'plugin:vue/recommended',
    'standard'
  ],
  // required to lint *.vue files
  plugins: ['vue'],
  // add your custom rules here
  rules: {}
}

I wait this code formated :

<template>
  <h1>Hello World</h1>
</template>

<script>
import seo from '~/plugins/seo'

export default {
  head () {
    return {
      title: 'Accueil',
      meta: [
        ...seo.title('Accueil')
      ]
    }
  }
}
</script>

The error in console :

Vetur initialized
[Error - 14:54:25] prettier-eslint [ERROR]:
Prettier-Eslint format failed
[Error - 14:54:25] No parser could be inferred for file: d:\DEV\NodeJS\clients\fast-luxury-service\v2\pages
[Error - 14:54:25] (node:16584) DeprecationWarning: The 'parserOptions.ecmaFeatures.experimentalObjectRestSpread' option is deprecated. Use 'parserOptions.ecmaVersion' instead. (found in "standard")

Reproducible Case

  1. Create project from Veturpack
  2. install packages :
yarn add --dev eslint eslint-config-standard eslint-friendly-formatter eslint-loader eslint-plugin-import eslint-plugin-node eslint-plugin-promise eslint-plugin-standard eslint-plugin-vue babel-eslint
  1. rewrite .eslintrc to
{
  "root": true,
  "env": {
    "es6": true,
    "browser": true,
    "node": true
  },
  "parserOptions": {
    "parser": "babel-eslint"
  },
  "extends": [
    "plugin:vue/recommended",
    "standard"
  ],
  "plugins": ["vue"],
  "rules": {
    "vue/html-self-closing": "off",
    "quotes": ["error", "double"]
  }
}

And now when we format .vue like Counter.vue the file is not formatted /wrong format.

OR

  1. Create project from nuxt-starter-template (https://github.com/nuxt-community/starter-template)
  2. Try format an .vue file (like /pages/index.vue) and here the file is not format, this generate the same error of my problem.

Suggestion

I have try fix this bug and probably we can use prettier-eslint v8.8.2 and use pass all .vue file for fix it.

UPDATE : I have find an solution (https://alligator.io/vuejs/eslint-vue-vetur/) but i keep this issue open because this is not right to make that for can use it

Thanks

formatting

Most helpful comment

I think this pull request will solve this problem.

All 8 comments

@orblazer Can you confirm your prettier version by running yarn list prettier?

Seems to be caused by prettier as suggested by @Airkro:

Since v1.13.x, Pettier make a breaking change. And prettier/prettier@1350edc didn't fix it, just trigger a warning.

When I install Pettier 1.13.x, VLS output No parser could be inferred for file.

@octref when i try with veture is exactly same error as @Airkro.

And the resul of yarn list prettier :
image

Holy cow spent over an hour on this. This is definitely still a bug. Reverted to prettier 1.12.1 and instantly/magically started working.

OSX High Sierra.
VSCode 1.25.1

Everything else is also the latest.

Also broken for me. I have to use "vetur.format.defaultFormatter.js": "vscode-typescript", to get it working.

Otherwise I get same error:

Prettier-Eslint format failed
No parser could be inferred 

I have same issue. I have to use "vetur.format.defaultFormatter.js": "vscode-typescript", to get it working.

"vetur.format.defaultFormatter.js": "prettier" not work

I think this pull request will solve this problem.

@russellr86 How to revert a VSCode extension to a specified version?

I see there's a PR for this, but until the next release:
Set "prettier.eslintIntegration": false in your workspace settings. Vetur assumes there's an .eslintrc file in the workspace if prettier.eslintIntegration is enabled. If it's not present, you get the above error (I think this is what's happening)

Was this page helpful?
0 / 5 - 0 ratings