adobe-research / node-theseus

76 stars 13 forks source link

Starting sails.js 0.10.0-rc5 app.js fails, but works fine at 0.9.16 #18

Closed blah238 closed 10 years ago

blah238 commented 10 years ago

I have managed to get node-theseus to launch a sails.js app at 0.9.16 (stable) but at 0.10.0-rc5 (beta) it fails with the following error:

root@nodejs sf_vm-share/test_app# node-theseus --theseus-verbose=2 app.js --port=3000
[node-theseus] adding require() instrumentation hook
[node-theseus] listening for WebSocket connections on port 8888
[node-theseus] instrumenting /media/sf_vm-share/test_app/app.js ...
exception during parsing /media/sf_vm-share/test_app/app.js Error: Line 32: Illegal return statement
    at throwError (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:1161:21)
    at throwErrorTolerant (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:1172:24)
    at parseReturnStatement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2478:13)
    at parseStatement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2754:24)
    at /usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3598:38
    at parseSourceElement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3046:24)
    at parseStatementList (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2043:25)
    at parseBlock (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2058:17)
    at /usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3598:38
    at parseCatchClause (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2668:19)
exception during parsing /media/sf_vm-share/test_app/app.js Error: Line 32: Illegal return statement
    at throwError (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:1161:21)
    at throwErrorTolerant (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:1172:24)
    at parseReturnStatement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2478:13)
    at parseStatement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2754:24)
    at /usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3598:38
    at parseSourceElement (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3046:24)
    at parseStatementList (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2043:25)
    at parseBlock (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2058:17)
    at /usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:3598:38
    at parseCatchClause (/usr/local/lib/node_modules/node-theseus/node_modules/fondue/node_modules/falafel/node_modules/esprima/esprima.js:2668:19)
[node-theseus] caught uncaught exception

/usr/local/lib/node_modules/node-theseus/node-theseus.js:156
                        var map = content.map().toString();
                     ^
TypeError: Property 'map' of object /**
 * app.js
 *
 * Use `app.js` to run your app without `sails lift`.
 * To start the server, run: `node app.js`.
 *
 * This is handy in situations where the sails CLI is not relevant or useful.
 *
 * For example:
 *   => `node app.js`
 *   => `forever start app.js`
 *   => `node debug app.js`
 *   => `modulus deploy`
 *   => `heroku scale`
 *
 *
 * The same command-line arguments are supported, e.g.:
 * `node app.js --silent --port=80 --prod`
 */

// Ensure a "sails" can be located:
var sails;
try {
        sails = require('sails');
} catch (e) {
        console.error('To run an app using `node app.js`, you usually need to have a version of `sails` installed in the same directory as your app.');
        console.error('To do that, run `npm install sails`');
        console.error('');
        console.error('Alternatively, if you have sails installed globally (i.e. you did `npm install -g sails`), you can use `sails lift`.');
        console.error('When you run `sails lift`, your app will still use a local `./node_modules/sails` dependency if it exists,');
        console.error('but if it doesn\'t, the app will run with the global sails instead!');
        return;
}

// Try to get `rc` dependency
var rc;
try {
        rc = require('rc');
} catch (e0) {
        try {
                rc = require('sails/node_modules/rc');
        } catch (e1) {
                console.error('Could not find dependency: `rc`.');
                console.error('Your `.sailsrc` file(s) will be ignored.');
                console.error('To resolve this, run:');
                console.error('npm install rc --save');
                rc = function () { return {}; };
        }
}

// Start server
sails.lift(rc('sails'));
 is not a function
    at Object.Module._extensions..js (/usr/local/lib/node_modules/node-theseus/node-theseus.js:156:22)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.exports.launch (/usr/local/lib/node_modules/node-theseus/node-theseus.js:91:2)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-theseus/bin/node-theseus:98:14)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
[node-theseus] caught process.exit() 1 time, not exiting

Any ideas as to what may be going wrong here?

alltom commented 10 years ago

I don't think it likes that return statement in the catch block at the top-level. It's not inside any function. Apparently Node.js is fine with that and treats it as if the whole module is being evaluated inside a function.

Hmm.

Since it's in your code, could you just remove the return statement? If using return like that is idiomatic, I should find a way to support it, but I don't think I've seen it before.

alltom commented 10 years ago

Sorry it took so long to respond. I wish I could have responded "19 days ago", but hopefully this problem hasn't kept you up at night. :)

blah238 commented 10 years ago

Whoops, sorry I missed your response until now. That was exactly it. I commented out the return statement and it works! I will let the Sails.js guys know. Thanks!