4

I am trying to run one of the sample projects using appjs which is present over here https://github.com/appjs/appjs/tree/master/examples. I am using the latest version of node.js (v4.1.0 ) on Windows (64 bit machine)

When I try and run the example using the below command on Command Prompt

node --harmony index.js

I get an error as follows,

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)

I tried searching for this issue but I couldn't find a solution. Can anyone tell me how to use node.js with the harmony flag?

UPDATE My index.js looks like this

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()));
});
}

Now with v0.12 of Node.js I get below error

    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)
Parth Doshi
  • 4,200
  • 15
  • 79
  • 129
  • 1
    The conditional that causes it is here: `if (typeof Proxy !== 'object' || typeof WeakMap !== 'function') {` you won't find any info about this by searching, i suggest instead going to the module's issue tracker, Seems it may simply be incompatible with node.js 4 – Kevin B Sep 17 '15 at 16:19
  • ok so in that case do I need to use a lower version of node.js to get this working? – Parth Doshi Sep 17 '15 at 16:22
  • That's where i would start. – Kevin B Sep 17 '15 at 16:22
  • This link [http://stackoverflow.com/questions/28388885/ecmascript-6-features-available-in-node-js-0-12] suggests that v0.12 contains harmony flag. Can u tell me if I can go ahead with v0.12 – Parth Doshi Sep 17 '15 at 16:28
  • Yes, version 0.12 does have the harmony flag. I currently use 0.12.7 – Kevin B Sep 17 '15 at 16:33
  • Hi I tried using v0.12 but still i get the same issue. Please see the updated question – Parth Doshi Sep 17 '15 at 16:45
  • None of your code is relevant by the way. – Kevin B Sep 17 '15 at 16:53
  • I am not able to understand. Is it a problem with node.js or am I running it in the wrong way? – Parth Doshi Sep 17 '15 at 16:56
  • It's a problem with the module you are using, and in some way related to the version of node.js you are using and/or the way you're starting the app. – Kevin B Sep 17 '15 at 16:56
  • the version I am using now is v0.12.6. I checked that using the node -v command. The module i am using is appjs and github. I start the app using the command node --harmony index.js ...as mentioned over here [https://github.com/appjs/appjs/blob/master/examples/octosocial/octosocial.sh] – Parth Doshi Sep 17 '15 at 17:00
  • right, and all of that looks correct. but, if you were properly starting it with the harmony flag, `Proxy` and `WeakMap` would be defined. so, something's not quite right. – Kevin B Sep 17 '15 at 17:01
  • Any ideas on how should I try and debug this? Have you tried running appjs using the harmony flag? – Parth Doshi Sep 17 '15 at 17:05
  • @KevinB : any ideas how to proceed further? – Parth Doshi Sep 18 '15 at 06:14

1 Answers1

2

Just tested your code out locally with node v0.12.7 and v4.0.0. Looks like the node_modules/appjs/lib/index.js check makes sure that proxy is enabled no matter what.

By default the --harmony flag does not enable proxies. However you can use --harmony_proxies.

To help you understand what is happening:

  1. Open node in your terminal, Then type Proxy. You will get 'Proxy is not defined'.

  2. Now, open node --harmony in your terminal and do the same. You will get the same output.

  3. Now, with node --harmony-proxies. Bam, you get an empty object.

You should be able to run this with v4.x.x however, you will still need the proxies flag for harmony.

When the merge happened with node.js and io.js for v4 they released a page of ES6 features that are shipped if you are using 4.x.x. https://nodejs.org/en/docs/es6/

https://github.com/appjs/appjs is deprecated btw, but once you pass the module's test of features, it will require 32bit ;)

Edit:

To properly run your app use the following:

node --harmony-proxies index.js

Here is a screenshot to show the expected output from step 3 above. enter image description here

technicallyjosh
  • 3,511
  • 15
  • 17
  • hi. I have some doubts. I am using node version v.0.12.6 currently. When I type Proxy i get 'Proxy is not defined'. When I type node --harmony and node --harmony-proxies. I get the same output. How did u set the proxies flag on v0.12.6 or v.4.x.x. ? – Parth Doshi Sep 21 '15 at 01:49
  • @ParthDoshi I cannot reproduce the issue with 0.12.6. I just tried it with `node --harmony-proxies`, typed `Proxy` and got back `{}` – technicallyjosh Sep 21 '15 at 01:51
  • @ParthDoshi I've attached a screenshot of what my answer yields. – technicallyjosh Sep 21 '15 at 01:55
  • ohh ok now even I get the same output as yours. Can u tell how to run this using harmony flag and v0.12.6 [https://github.com/appjs/appjs/blob/master/examples/octosocial/octosocial.sh] – Parth Doshi Sep 21 '15 at 01:58
  • I've added the proper command right above the screenshot :) A side note: His error messaging is wrong as running with the standard --harmony flag is incorrect. – technicallyjosh Sep 21 '15 at 02:00
  • I tried your command on both v.4.x and v0.12.6. on v4.x i get an error saying "Error: AppJS .node file not found at Object. (F:\softwares\Node.js\node_modules\appjs\lib\bindings. js:19:9)" and on v.12.6 I get an error "Error: AppJS requires Node.js v0.8 at Object. (F:\softwares\Node.js_v0.12\node_modules\appjs\lib\bin dings.js:9:9)" – Parth Doshi Sep 21 '15 at 02:03
  • Now that's an entire new question :) since this uses native bindings it looks like only 0.8.x is supported. last commit to that project was in 2014... a lot has changed since then. you could try re-building the bindings using [node-gyp](https://github.com/nodejs/node-gyp). another option is to go with another native wrapper kit such as [nwjs](https://github.com/nwjs) or [electron](https://github.com/atom/electron) – technicallyjosh Sep 21 '15 at 02:07
  • should I use the v0.8 for now and may be later try building node for other versions? – Parth Doshi Sep 21 '15 at 02:18
  • i would honestly look at another solution for a native type app. It's up to you though. I was mainly trying to help you out on the --harmony flag issue :) – technicallyjosh Sep 21 '15 at 02:33
  • what do you mean by another solution for a native type app? Do you mean alternatives for appjs? What are they if you know any? – Parth Doshi Sep 21 '15 at 02:35
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/90188/discussion-between-technicallyjosh-and-parth-doshi). – technicallyjosh Sep 21 '15 at 02:35