简体   繁体   中英

node.js modules: /usr/local/lib/node_modules/fpm/bin/iffront:49: “SyntaxError: Unexpected token )”

I have followed the steps here to create my first node.js desktop application, but I get this error after trying pack the application:

/usr/local/lib/node_modules/fpm/bin/iffront:49
var getRoot = () => {
               ^
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

I get the same error when I run $ fpm --help .

I have installed fpm using sudo npm install -g --save fpm

This is the code at /usr/local/lib/node_modules/fpm/bin/iffront:49

#!/usr/bin/env node

"use strict";

process.bin = process.title = 'iffront';

var path = require('path');
var fs = require('fs');
var os = require('os');
var mout = require('mout');
var osenv = require('osenv');
var iffront = require('../lib');
var pkg = require(path.join(__dirname, '..', 'package.json'));
var cli = require('../lib/util/cli');
var updateNotifier = require('update-notifier');
var colors = require('../lib/util/colors');

var options;
var command;
var commandFunc;
var notifier;

options = cli.readOptions({
    version: { type: Boolean, shorthand: 'v' }
});

if (options.version) {
    process.stdout.write(pkg.version + '\n');
    process.exit();
}

while (options.argv.remain.length) {
    command = options.argv.remain.join(' ');

    //Alias lookup
    if (iffront.abbreviations[command]) {
        command = iffront.abbreviations[command].replace(/\s/g, '.');
        break;
    }
    command = command.replace(/s/g, '.');
    // Direct lookup
    if (mout.object.has(iffront.commands, command)) {
        break;
    }
    options.argv.remain.pop();
}

// 在执行命令前,先判断是否有全局的安装包支持。
var getRoot = () => { //THIS IS THE LINE 49
  var platform = os.platform();
  var root;
  if (platform === 'win32') {
      root = path.parse(process.cwd()).root;
  } else {
      root = os.homedir();
  }
  return root;
};

Im on Ubuntu 14.04 LTS.

The code you are using is arrow function of EcmaScript 6. You need to update to latest version of node, or you could run the 0.10 version with --harmony flag.

Update: to update the node version, you could use nvm https://github.com/creationix/nvm

If you plan to use more features of ES6, you should instead compile your code using babel . As even Node v5.0.0 implements only 59% of ES6 features as of today.

Check this link for ES6 compatibility table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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