最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can't use template strings in node.js - Stack Overflow

programmeradmin3浏览0评论

According to MDN, Template Strings should be working in Chrome, and by extension V8 on which Node.js is based on; but when I try the following I get a syntax error:

var name = 'coffee';
console.log(`Hello, ${name}!`);

running node file.js just results in a SyntaxError: Unexpected token ILLEGAL

Is there some kind of flag I need to enable to use this feature, or is it simply not implemented in node?

According to MDN, Template Strings should be working in Chrome, and by extension V8 on which Node.js is based on; but when I try the following I get a syntax error:

var name = 'coffee';
console.log(`Hello, ${name}!`);

running node file.js just results in a SyntaxError: Unexpected token ILLEGAL

Is there some kind of flag I need to enable to use this feature, or is it simply not implemented in node?

Share Improve this question asked Sep 29, 2015 at 13:09 Electric CoffeeElectric Coffee 12.1k10 gold badges72 silver badges139 bronze badges 4
  • 3 What version of node.js are you using? only v4.0.0 and above support template strings. – Touffy Commented Sep 29, 2015 at 13:10
  • For whatever reason I have v0.12.7, and I downloaded it less than a month ago – Electric Coffee Commented Sep 29, 2015 at 13:15
  • 1 @ElectricCoffee: A month ago, v0.12.7 was indeed the current version. Since then, Node.js and io.js have merged back together (io.js was a fork) and the first recombined release was deemed to be v4.0.0 (since io.js had been using semver and was at v3.3.1). – T.J. Crowder Commented Sep 29, 2015 at 13:21
  • @T.J.Crowder oh they finally merged the projects, good – Electric Coffee Commented Sep 29, 2015 at 13:26
Add a comment  | 

1 Answer 1

Reset to default 23

Template strings were added in NodeJS v4.0.0. And I can confirm that they do work at least as far back as v4.1.1; I didn't bother to check v4.0.0, but I have no reason to doubt the linked announcement. No special runtime flag is required.

发布评论

评论列表(0)

  1. 暂无评论