【问题标题】:module is not defined and process is not defined in eslint in visual studio code模块未定义且进程未在 Visual Studio 代码中的 eslint 中定义
【发布时间】:2018-09-22 04:06:51
【问题描述】:

我已经在我的机器上安装了 eslint,并且我使用了 Visual Studio 代码 我有某些模块和流程要导出 当我尝试使用“模块”或“进程”时,它显示 它以前工作正常。

[eslint] 'module' is not defined. (no-undef)
[eslint] 'process' is not defined. (no-undef)

这是我的 .eslintrc.json

{

"env": {
    "browser": true,
    "amd": true

},
"parserOptions": {
    "ecmaVersion": 6
  },
"extends": "eslint:recommended",
"rules": {
    "no-console": "off",
    "indent": [
        "error",
        "tab"
    ],
    "linebreak-style": [
        "error",
        "windows"
    ],
    "quotes": [
        "error",
        "single"
    ],
    "semi": [
        "error",
        "always"
    ]
}

}

我想删除这个错误

【问题讨论】:

  • 我找到了,谢谢。我们需要添加“globals”:{“angular”:false,“module”:false,“inject”:false,“document”:false},“env”:{“browser”:true,“amd”:true , "node": true } 在 .eslintrc.json 文件中
  • 谢谢 :) 这对我有用。你应该用一个简单的例子来回答这个问题。

标签: module process eslint


【解决方案1】:

您可能正在尝试在节点环境中运行它。

env 部分应如下所示:

"env": {
    "browser": true,
    "amd": true,
    "node": true
},

【讨论】:

  • 注意:这需要放在你的 .eslintrc 文件中
  • 此配置的browseramd 部分不需要解决此特定错误。
【解决方案2】:

在您的 ESLint 配置文件中,只需添加以下内容:

{
  ...
  env: {
    node: true
  }
  ...
}

这应该可以解决 "module" is not defined"process" is not defined 错误。

假设您在 Node 环境中运行。还有用于浏览器环境的browser 选项。您可以根据需要同时申请两者。

如果您想防止 ESLint 对某些全局变量进行 linting,则需要在配置的 globals 部分中添加特定的全局变量。

globals: {
  window: true,
  module: true
}

【讨论】:

  • 添加node:true 为我解决了这个问题。谢谢!
【解决方案3】:

您需要tell eslint that you are in a Node environment。对于像gulpfile.js 这样的一次性文件,我最喜欢的做法是在顶部添加以下评论:

/* eslint-env node */

【讨论】:

  • 前端代码的完美解决方案,在全局指定这显然是错误的。谢谢!
  • 这应该是公认的答案。以最直接、最客观的方式消除问题。
  • 接受的答案太宽泛了,你不想在任何地方都允许节点语法,只在一个文件中。
猜你喜欢
  • 2018-11-26
  • 2016-08-27
  • 2022-01-12
  • 2018-02-12
  • 1970-01-01
  • 1970-01-01
  • 2020-03-15
  • 1970-01-01
  • 2020-12-08
相关资源
最近更新 更多