Why I can not start harmony mode by “node --harmony test.js” from command line?

妖精的绣舞 提交于 2019-12-04 06:32:18

问题


The problem is:

longhao33@hePC:~$ node --harmony test.js 
/home/longhao33/test.js:1
(function (exports, require, module, __filename, __dirname) { let str = 'es666666666666';
                                                              ^^^

SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:413:25)
    at Object.Module._extensions..js (module.js:452:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:475:10)
    at startup (node.js:117:18)
    at node.js:951:3

But "let" is supported when:(So strange!)

longhao33@hePC:~$ node --harmony
> let str = 'es66666666666'
undefined
> str
'es66666666666'
  1. system:ubuntu 14.04LTS 64bit
  2. node:V4.1.1 (Installed by nvm,which is installed at $HOME)
  3. content of test.js:

    let str = 'es666666666666'; console.log(str);

Thanks ahead of time.


回答1:


You're missing 'use strict'; at the top of your test.js (as indicated by the error message).

It works in the REPL because 'use strict'; is automatically included during code evaluation.



来源:https://stackoverflow.com/questions/32891755/why-i-can-not-start-harmony-mode-by-node-harmony-test-js-from-command-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!