Javascript 箭头函数语法 (=>)' 仅在 ES6 中可用(使用 'esversion: 6')

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42866159/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 01:28:42  来源:igfitidea点击:

arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6')

javascriptgruntjsecmascript-6jshintgrunt-contrib-jshint

提问by Rafael C.

Currently I'm running my tests with protractor/grunt but I'm getting the follow error message:

目前我正在使用量角器/咕噜声运行我的测试,但我收到以下错误消息:

'arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6').

I think my .jshintrcfile is not being read, because I've added this condition.

我认为我的.jshintrc文件没有被读取,因为我已经添加了这个条件。

.jshintrc

.jshintrc

{ 
  "esversion": 6 
}

Gruntfile.js

Gruntfile.js

jshint : {
  all: ["tests/API/**/*.js"],
  options: {
    undef: true,
    mocha: true,
    node: true,
    jshintrc: true,
    esversion: 6,
    globals: {
      require: true,
      module: true,
      console: true,
      esversion: 6,
      }
  },
  ui: ["tests/UI/**/*.js"],
  options: {
    undef: true,
    mocha: true,
    node: true,
    jshintrc: true,
    esversion: 6,
    globals: {
      require: true,
      module: true,
      console: true,
      esversion: 6,
      jshintrc: true,
    }
  }
}

Any idea to solve this problem?

有什么想法可以解决这个问题吗?

回答by Rafael C.

I was able to resolve this issue by adding this block of code at the top of each file.js that accused the error

我能够通过在每个指责错误的 file.js 的顶部添加这段代码来解决这个问题

/*jshint esversion: 6 */

Example:

例子:

enter image description here

在此处输入图片说明

回答by Kushal Shinde

It is not possible to add /*jshint esversion: 6 */in each file.js file.

不可能/*jshint esversion: 6 */在每个 file.js 文件中添加。

Instead of above, please do below changes if you are using Visual Studio Code: -

如果您使用的是 Visual Studio Code,请不要进行以上更改:-

  1. Open Visual Studio Code
  2. File -> Preferences -> Settings
  3. Default User Settings -> JSHint configuration
  4. look for "jshint.options": {},
  5. change it to "jshint.options": {"esversion": 6},by clicking on Edit on the left
  1. 打开 Visual Studio 代码
  2. 文件 -> 首选项 -> 设置
  3. 默认用户设置 -> JSHint 配置
  4. 寻找 "jshint.options": {},
  5. "jshint.options": {"esversion": 6},单击左侧的编辑将其更改为

回答by Nadeem Yasin

You can do more project-specific settings by following these steps.

您可以按照以下步骤进行更多特定于项目的设置。

  1. Create a folder with the name of .vscodeat the root of your project directory
  2. Create a file with the name settings.json
  3. Add the following content into it.
  1. .vscode在项目目录的根目录创建一个名为 的文件夹
  2. 创建一个文件名 settings.json
  3. 将以下内容加入其中。
{
  "jshint.options": {
    "esversion": 6
  }
}
{
  "jshint.options": {
    "esversion": 6
  }
}

You can add some more settings to keep things consistents across your team.

您可以添加更多设置以保持整个团队的一致性。

{
    "editor.tabSize": 2,
    "editor.formatOnSave": true,
    "editor.formatOnType": true, 
    "jshint.options": {
        "esversion": 6
    }
}

回答by Daisy liu

I have this problem after I installed JSHint. The process for me to solve this problem as below: Preference -> setting -> Extensions -> JSHint Configuration -> options -> add "jshint.options": {"esversion": 6} Done.

我安装 JSHint 后遇到了这个问题。我解决这个问题的过程如下:首选项 -> 设置 -> 扩展 -> JSHint 配置 -> 选项 -> 添加 "jshint.options": {"esversion": 6} 完成。