【问题标题】:import ``,ESLint: Cannot read property 'range' of null Occurred while linting导入``,ESLint:无法读取null的属性“范围” linting时发生
【发布时间】:2020-05-08 03:28:47
【问题描述】:

错误是因为这行代码

item.component = () => import(`@/views/${_component}`)

如果我修改.eslintrc.js,它可以工作

'indent' : "off",
'template-curly-spacing' : "off",

但是这样,eslint 不会帮我格式化代码

当我运行以下代码时,他不能工作,但是eslint没有错误:

item.component = () => import(`@/views/` + _component)
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.0.1",
"eslint": "5.15.3",

节点-v:v12.9.1

eslint -v: v6.8.0

vscode

【问题讨论】:

    标签: eslint


    【解决方案1】:

    尝试将您的 eslint 缩进规则 设置为包含: ignoredNodes 用于模板文字。我的eslintrc.js 有以下内容:

    rules: {
      indent: [2, "tab", { 
        ignoredNodes: ["TemplateLiteral"] 
      }],
      ... etc ...
    }
    

    这将忽略扩展的template literals

    如果上述方法不起作用,请尝试删除:package.jsonnode_modules,然后使用 npm iyarn 重新安装。

    【讨论】:

    • 这对我来说适用于 Vue。调整我的 ESLint 设置后,它不再允许我 import Vue from 'vue'。这解决了这个问题。
    • 您的意思是尝试删除package-lock.jsonnode_modules,而不是package.json
    • not package.json 你会得到所有的包引用。这很关键。 @ToddHale
    猜你喜欢
    • 2018-07-01
    • 2019-05-01
    • 2018-06-28
    • 2017-08-16
    • 2021-07-16
    • 2022-01-16
    • 1970-01-01
    • 2021-06-08
    相关资源
    最近更新 更多