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
arrow function syntax (=>)' is only available in ES6 (use 'esversion: 6')
提问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.
回答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,请不要进行以上更改:-
- Open Visual Studio Code
- File -> Preferences -> Settings
- Default User Settings -> JSHint configuration
- look for
"jshint.options": {}, - change it to
"jshint.options": {"esversion": 6},by clicking on Edit on the left
- 打开 Visual Studio 代码
- 文件 -> 首选项 -> 设置
- 默认用户设置 -> JSHint 配置
- 寻找
"jshint.options": {}, "jshint.options": {"esversion": 6},单击左侧的编辑将其更改为
回答by Nadeem Yasin
You can do more project-specific settings by following these steps.
您可以按照以下步骤进行更多特定于项目的设置。
- Create a folder with the name of
.vscodeat the root of your project directory - Create a file with the name
settings.json - Add the following content into it.
.vscode在项目目录的根目录创建一个名为 的文件夹- 创建一个文件名
settings.json - 将以下内容加入其中。
{ "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} 完成。


