【原创】Eslint 常见报错

Extra semicolon

转自:https://www.cnblogs.com/cowboybusy/p/10633286.html
末尾分号检测,如果不想检测该项,可以在配置文件中添加
semi: 0

Expected indentation of 2 spaces but found 4

转自:https://blog.csdn.net/qq_35132089/article/details/105887879
该问题是使用 ESLint 插件导致的
作为一个代码规范插件,ESLint 限定缩进是 2 个空格,而我们一般使用 Tab 键的缩进是 4 个空格。
解决:关闭 ESLint 这个检查规则。
打开 .eslintrc.js 配置文件,加入一行配置 indent:["off",2]

imported multiple times import/no-duplicates

转自:https://stackoverflow.com/questions/58757122/update-of-eslint-gives-the-following-error-imported-multiple-times-import-no-du

该问题是我引入 jQuery 时写成:

import $ from 'jquery';
import jQuery from 'jquery';

修改为如下即可

import { $, jQuery } from 'jquery';

Uncaught TypeError: (0 , jquery__WEBPACK_IMPORTED_MODULE_1__.$) is not a function

以上错误为引入 jQuery 失败。
转自:https://blog.51cto.com/tianma3798/4669388
原因是上面 import { $, jQuery } from 'jquery'; 引入jQuery 失败。
还是要修改为 import $ from 'jquery';
之后在 .eslintrc.js 配置文件中加入:jquery: true 即可。如下:

    env: {
        browser: true,
        commonjs: true,
        es2021: true,
        jquery: true
    },

修改后,全部配置文件内容如下:

module.exports = {
    env: {
        browser: true,
        commonjs: true,
        es2021: true,
        jquery: true
    },
    extends: [
        'plugin:vue/essential',
        'standard'
    ],
    parserOptions: {
        ecmaVersion: 12
    },
    plugins: [
        'vue'
    ],
    rules: {
        indent: ['off', 2],
        semi: 0,
        'no-unused-vars': 'off'
    }
};
点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注