Framework FAQs
I use a framework (like Vue) that requires custom file extensions
In order to use extra file types you'll need to provide parserOptions.extraFileExtensions to specify an array of non-TypeScript extensions to allow.
See Changes to extraFileExtensions with projectService to avoid performance issues.
- Flat Config
- Legacy Config
export default defineConfig({
// If you're using a files/extends setup, be sure to include your extra file
// type here, too:
files: ['**/*.{js,ts}'],
files: ['**/*.{js,ts,vue}'],
// ... the rest of your config ...
languageOptions: {
parserOptions: {
extraFileExtensions: ['.vue'],
projectService: true,
},
},
});
If you forget to include extraFileExtensions: ['.vue'], you'll likely see error messages like "You should add parserOptions.extraFileExtensions to your config" appearing when ESLint attempts to run on the extra file type.
module.exports = {
// ... the rest of your config ...
parserOptions: {
extraFileExtensions: ['.vue'],
projectService: true,
tsconfigRootDir: __dirname,
},
};
I am running into errors when parsing TypeScript in my .vue files
If you are running into issues parsing .vue files, it might be because parsers like vue-eslint-parser are required to parse .vue files. In this case you can move @typescript-eslint/parser inside parserOptions and use vue-eslint-parser as the top level parser.
- Flat Config
- Legacy Config
import tseslint from 'typescript-eslint';
import { defineConfig } from 'eslint/config';
import vueParser from 'vue-eslint-parser';
export default defineConfig(
// ... the rest of your config ...
{
languageOptions: {
parser: tseslint.parser,
parser: vueParser,
parserOptions: {
parser: tseslint.parser,
sourceType: 'module',
},
},
},
);
module.exports = {
// ... the rest of your config ...
parser: '@typescript-eslint/parser',
parser: 'vue-eslint-parser',
parserOptions: {
parser: '@typescript-eslint/parser',
extraFileExtensions: ['.vue'],
},
};
The parserOptions.parser option can also specify an object to specify multiple parsers. See the vue-eslint-parser usage guide for more details.