4

我正在尝试使用此处https://github.com/appjs/appjs/tree/master/examples上的appjs运行示例项目之一。我在 Windows(64 位机器)上使用最新版本的 node.js (v4.1.0)

当我尝试在命令提示符上使用以下命令运行示例时

节点 --harmony index.js

我收到如下错误,

Error: AppJS requires Node is run with the --harmony command line flag
at Object.<anonymous> (F:\programs\appjs_examples\node_modules\appjs\lib\ind
ex.js:2:9)
at Module._compile (module.js:434:26)
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 Module.require (module.js:365:17)
at require (module.js:384:17)
at Object.<anonymous> (F:\programs\appjs_examples\octosocial\index.js:1:73)
at Module._compile (module.js:434:26)
at Object.Module._extensions..js (module.js:452:10)

我尝试搜索此问题,但找不到解决方案。谁能告诉我如何使用带有和谐标志的node.js?

更新 我的 index.js 看起来像这样

var app = require('appjs'),
github = new (require('github'))({ version: '3.0.0' }),
KEY_F12 = process.platform === 'darwin' ? 63247 : 123;

app.serveFilesFrom(__dirname + '/assets');

var window = app.createWindow({
 width: 460,
  height: 640,
 resizable: false,
  disableSecurity: true,
  icons: __dirname + '/assets/icons'
 });

  window.on('create', function(){
   window.frame.show();
   window.frame.center();
   });

 window.on('ready', function(){
   var $ = window.$,
  $username = $('input[name=username]'),
  $password = $('input[name=password]'),
  $info = $('#info-login'),
  $label = $info.find('span'),
  $buttons = $('input, button');

 $(window).on('keydown', function(e){
  if (e.keyCode === KEY_F12) {
    window.frame.openDevTools();
  }
});

 $username.focus();

 $('#login-form').submit(function(e){
e.preventDefault();

$info.removeClass('error').addClass('success');
$label.text('Logging in...');
$buttons.attr('disabled', true);

  github.authenticate({
    type: 'basic',
   username: $username.val(),
  password: $password.val()
   });

github.user.get({}, function(err, result) {
  if (err) {
    $info.removeClass('success').addClass('error');
    $label.text('Login Failed. Try Again.');
    $buttons.removeAttr('disabled');
  } else {
    loggedIn(result);
  }
  });
});

 function loggedIn(result){
    $label.text('Logged in!');
    $('#user-avatar').append('<img src="'+result.avatar_url+'" width="64" height="64">');
   $('#user-name').text(result.name);
    $('#login-section').hide();
    $('#profile-section').show();
    ['Followers', 'Following'].forEach(function(type){
      github.user['get'+type]({ user: result.login }, populate.bind(null,     type.toLowerCase()));
});
}

现在使用Node.js 的v0.12我得到以下错误

    F:\softwares\Node.js_v0.12\node_modules\appjs\lib\index.js:2
throw new Error ('AppJS requires Node is run with the --harmony command line
  Error: AppJS requires Node is run with the --harmony command line flag
  at Object.<anonymous> (F:\softwares\Node.js_v0.12\node_modules\appjs\lib\ind
ex.js:2:9)
   at Module._compile (module.js:460:26)
   at Object.Module._extensions..js (module.js:478:10)
   at Module.load (module.js:355:32)
   at Function.Module._load (module.js:310:12)
   at Module.require (module.js:365:17)
   at require (module.js:384:17)
   at Object.<anonymous> (F:\softwares\Node.js_v0.12\index.js:1:73)
   at Module._compile (module.js:460:26)
   at Object.Module._extensions..js (module.js:478:10)
4

1 回答 1

2

刚刚使用节点 v0.12.7 和 v4.0.0 在本地测试了您的代码。看起来node_modules/appjs/lib/index.js检查确保无论如何启用代理。

默认情况下,该--harmony标志不启用代理。但是,您可以使用--harmony_proxies.

为了帮助您了解正在发生的事情:

  1. node在终端中打开,然后输入Proxy. 您将得到“未定义代理”。

  2. 现在,node --harmony在您的终端中打开并执行相同的操作。您将获得相同的输出。

  3. 现在,与node --harmony-proxies. Bam,你得到一个空物体。

您应该可以使用 v4.xx 运行它,但是您仍然需要代理标志才能和谐。

当 v4 的 node.js 和 io.js 发生合并时,如果您使用 4.xx https://nodejs.org/en/docs/es6/,他们发布了一个 ES6 功能页面

https://github.com/appjs/appjs顺便说一句已被弃用,但是一旦您通过了模块的功能测试,它将需要 32 位;)

编辑:

要正确运行您的应用程序,请使用以下命令:

node --harmony-proxies index.js

这是显示上述步骤 3 的预期输出的屏幕截图。 在此处输入图像描述

于 2015-09-20T23:01:26.433 回答