简体   繁体   English

ECMASCRIPT中的反引号:意外的令牌非法

[英]Backtick in ECMASCRIPT : Unexpected Token Illegal

I am writing a small test code in an ExpressJs app. 我正在ExpressJs应用程序中编写小的测试代码。 The code is as follows : 代码如下:

var express = require('express');
var app = express();
var dataFile = require('./data/data.json');


app.set('port', process.env.PORT || 3000);

app.get('/', function(req, res) {
  var info = '';
  dataFile.speakers.forEach(function(item) {
    info += `<li>
      <h2>${item.name}</h2>
      <p>${item.summary}</p>
    </li>
    `;
  });
  res.send(`
    <h1>My Meetups</h1>
    ${info}
    `);
});

var server = app.listen(app.get('port'), function() {
  console.log('Listening on port ' + app.get('port'));
});

When I try to execute the command 当我尝试执行命令时

node app/app.js 节点app / app.js

in Git bash terminal, I get the following error : 在Git bash终端中,出现以下错误:

> E:\expressjs\app\app.js:11
>     info += `<li>
>             ^ SyntaxError: Unexpected token ILLEGAL
>     at Module._compile (module.js:439:25)
>     at Object.Module._extensions..js (module.js:474:10)
>     at Module.load (module.js:356:32)
>     at Function.Module._load (module.js:312:12)
>     at Function.Module.runMain (module.js:497:10)
>     at startup (node.js:119:16)
>     at node.js:935:3

What I tried : 我试过了

  1. Checked node version : Using node 0.10.37 检查的节点版本:使用节点0.10.37
  2. Tried running the node command with --harmony option as suggested : Same error 尝试使用建议的--harmony选项运行node命令:相同错误
  3. Tried visiting the ECMA compatibility table website : Wasn't able to search the right information 尝试访问ECMA兼容性表网站:无法搜索正确的信息

Am using the Atom Editor 我正在使用Atom编辑器

What I suspect : Incompatible version of Node and ECMA 我怀疑:Node和ECMA的版本不兼容

Can someone help with this ? 有人可以帮忙吗?

Thanks 谢谢

Try this site. 试试这个网站。 It shows all es6 features implemented in nodeJS 它显示了在nodeJS中实现的所有es6功能

http://node.green/ http://node.green/

My suspect is that you using very old version of node(almost all features gives error in node 0.10). 我的怀疑是您使用的节点版本非常旧(几乎所有功能都在节点0.10中给出了错误)。

Try to upgrade into node6 and all should be OK. 尝试升级到node6,一切都应该没问题。

Hope this helps. 希望这可以帮助。

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

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