0

これが私の Node.js スクリプトです。

pDownload("http://serv/file", "localfile")
  .then( ()=> console.log('downloaded file no issues...'))
  .catch( e => console.error('error while downloading', e));

function pDownload(url, dest){} // Yes empty, for now

Node.js v0.10.25 (Ubuntu 2015.10 のデフォルト) で実行すると、括弧に関する次の構文エラーが表示されます。

/home/nico/main.js:2
  .then( ()=> console.log('downloaded file no issues...'))
          ^
SyntaxError: Unexpected token )
    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:902:3

どうすれば修正できますか?

4

1 に答える 1

-1

Node 0.10 の V8 のバージョンは矢印関数をサポートしていません。

次のいずれかで修正できます。

  • Babel などを使用してコードを ES5 にコンパイルする
  • または、5.x などの最新バージョンの Node を使用する
  • アロー関数を使う

(ありがとうジェームズ・アラダイス)

于 2016-02-10T10:32:22.423 に答える