简体   繁体   English

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

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

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 .jshintrc file 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?有什么想法可以解决这个问题吗?

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:例子:

在此处输入图片说明

It is not possible to add /*jshint esversion: 6 */ in each file.js file.无法在每个/*jshint esversion: 6 */文件中添加/*jshint esversion: 6 */

Instead of above, please do below changes if you are using Visual Studio Code: -如果您使用的是 Visual Studio Code,请不要进行以上更改:-

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

You can do more project-specific settings by following these steps.您可以按照以下步骤进行更多特定于项目的设置。

  1. Create a folder with the name of .vscode at the root of your project directory在项目目录的根目录创建一个名为.vscode的文件夹
  2. Create a file with the name settings.json创建一个名为settings.json的文件
  3. Add the following content into it.将以下内容加入其中。
 { "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
    }
}

Add the following into your package.json :将以下内容添加到您的package.json

"jshintConfig": {
  "esversion": 6
}

I have this problem after I installed JSHint.我安装 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.options": {"esversion": 6} 完成。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM