Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: Object [object Function] has no method 'apply' when running node-theseus on small example #16

Closed
ackalker opened this issue Jan 22, 2014 · 10 comments

Comments

@ackalker
Copy link

After installing Theseus and node-theseus, I tried running it on the following small sraping example using cheerio.

example.js:

/*jslint node:true*/
"use strict";

var cheerio = require('cheerio');
var $ = cheerio.load('<html><head></head><body><div id="content"><div id="sidebar"></div><div id="main"><div id="breadcrumbs"></div><table id="data"><tr><th>Name</th><th>Address</th></tr><tr><td class="name">John</td><td class="address">Address of John</td></tr><tr><td class="name">Susan</td><td class="address">Address of Susan</td></tr></table></div></div></body></html>');

$('#data .name').each(function () {
    console.log($(this).text());
});

The example runs just fine with the Node.js extension for Brackets, but running it with node-theseus I get the following error:

$ node-theseus example.js
[node-theseus] caught uncaught exception
TypeError: Object [object Function] has no method 'apply'
    at eval (eval at createTracer (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:169:14), <anonymous>:992:17)
    at Object.<anonymous> (/home/miki/proj/scraping/example.js.fondue:26:142)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:163:11)
    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 (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:91:2)
    at Object.<anonymous> (/home/miki/.local/lib/node_modules/node-theseus/bin/node-theseus:98:14)
[node-theseus] caught process.exit() 1 time, not exiting
^C

Brackets shows (0 calls) in the sidebar for line 7

Thinking it might have to do with the anonymous function which outputs the scrape results, I turned it into a named function.

example-test.js:

/*jslint node:true*/
"use strict";

var cheerio = require('cheerio');
var $ = cheerio.load('<html><head></head><body><div id="content"><div id="sidebar"></div><div id="main"><div id="breadcrumbs"></div><table id="data"><tr><th>Name</th><th>Address</th></tr><tr><td class="name">John</td><td class="address">Address of John</td></tr><tr><td class="name">Susan</td><td class="address">Address of Susan</td></tr></table></div></div></body></html>');

var output = function () {
    console.log($(this).text());
};

$('#data .name').each(output);

which now points the error and (0 calls) at the named function 'output':

$ node-theseus example-test.js
[node-theseus] caught uncaught exception
TypeError: Object [object Function] has no method 'apply'
    at eval (eval at createTracer (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:169:14), <anonymous>:992:17)
    at Object.<anonymous> (/home/miki/proj/scraping/example-test.js.fondue:31:149)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:163:11)
    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 (/home/miki/.local/lib/node_modules/node-theseus/node-theseus.js:91:2)
    at Object.<anonymous> (/home/miki/.local/lib/node_modules/node-theseus/bin/node-theseus:98:14)
[node-theseus] caught process.exit() 1 time, not exiting
^C

Using Theseus 0.4.8 installed from within Brackets, node-theseus@0.2.2 installed using npm install -g, cheerio@0.13.1 installed locally.

@ackalker
Copy link
Author

$ npm version
{ http_parser: '1.0',
  node: '0.10.24',
  v8: '3.14.5.9',
  ares: '1.9.0-DEV',
  uv: '0.10.21',
  zlib: '1.2.3',
  modules: '11',
  openssl: '1.0.1e',
  npm: '1.3.21' }

@ackalker
Copy link
Author

I've tried with node-theseus from Git: same problem.
From some searching, it looks a lot like adobe-research/fondue#10 and that it has been fixed there.
Sadly fondue's version number in Git is the same as on npm, so it isn't easy to test and install that without hacking around npm's install function (forcing install of Git version of fondue).
Please consider bumping both node-theseus and fondue version numbers to some kind of 'development' version (you can always set a 'stable' version for both in their package.json :) )

@alltom
Copy link
Member

alltom commented Jan 23, 2014

Ahh, sorry about that! I have it on my to-do list to release a new version of Theseus, but I'm behind. I have to synchronize node-theseus releases with Theseus releases because Theseus asks you to npm install node-theseus and sometimes (often) the changes are breaking.

... but what are these "development" and "stable" version numbers you mention? Is there a way of flagging a node-theseus release as "unstable, don't install this by default"?

@ackalker
Copy link
Author

Thanks for your quick reply! :)
First off, I'm no npm guru myself, for the 'definite` (if there's anything like that) answers you should probably ask some of the people with lots and lots of packages on http://npmjs.org/ .
How you version has a lot to do with your project workflow (e.g. if you use multiple Git branches for release and development), and whether you're maintaining a group of closely related modules which evolve together.

There are some niceties in npm which can make your work much easier:

  • You can bump a module's version number and commit that bump in Git in one step: see npm help version
  • There are lots of ways of specifying versions and version ranges, in particular the '~' and '<' operators are very useful when dealing with pre-release versions: see npm help semver
  • You can 'tag' a specific module's version after you've published it, and use this tag instead of a version string when specifying that module as a dependency: see npm help tag

Hope this helps :)

@ackalker
Copy link
Author

You can also consider adding pinned versions of your dependencies as submodules in the main Git repository: see npm help submodule. AFAICT these will then be ignored by 'npm install', so it won't pull in the wrong versions of these dependencies.

This will make it much easier for people to clone your repository (and its submodules!) and have a consistent working set to hack on. Of course, when publishing, you should still make sure that particular versions of your module go together with their dependencies as published on npmjs.org. This probably means you will have to work with separate 'release version' branches for each version you publish.

@alltom
Copy link
Member

alltom commented Jan 23, 2014

Got it, lots of options. :) Well I have some reading to do then. In the meantime, I'm going to push new versions of everything. Probably not today, but in the next few days I hope.

If this is urgent for you, what I do locally is check out fondue right in node-theseus's node_modules directory.

Hope this helps. Thanks for all the pointers!

@ackalker
Copy link
Author

Good luck :)
Yep, I already updated fondue in my local branch. Here's how I did it

$ # Setup local branch
$ git checkout -b hacking
$ # Install (override) fondue from Git and update package.json for easy `npm install -g`
$ npm install git://github.com/adobe-research/fondue --save

Isn't npm awesome? :)

@ackalker
Copy link
Author

There's a much easier way :)
Though I've been using npm for a while, I'm learning new things every time: you can use npm link to solve all problems above. I just didn't think it would work well for modules with command-line scripts in them.
Please consider adding following setup as an example for hacking on node-theseus to README.md / Wiki / etc. for others to use.

  1. Setup working environment
$ mkdir adobe-research
$ cd adobe-research
$ git clone git://github.com/adobe-research/node-theseus
$ git clone git://github.com/adobe-research/fondue
  1. Install dependencies from npm repository
$ cd fondue
$ npm install
$ cd ../node-theseus # pulls in outdated version of fondue, will be corrected in next step
$ npm install
  1. Link to development versions
$ # Create both a global link to development version of fondue *and* a link from node-theseus to this global link to fondue, using `npm link`'s "two-step shortcut" (see `npm help link`)
$ npm link ../fondue # Does _not_ create a global link to bin/fondue script (which is a good thing)
$ # Finally, create a global link to node-theseus, this _does_ create a global link to the bin/node-theseus script (which is what we want)
$ npm link # Works like `install -g`, except creates symlinks instead of fetching everything from the registry

That's it. But please do keep those version numbers updated :-)

@alltom
Copy link
Member

alltom commented Feb 10, 2014

Finally published the version with the fix. (I'm really sorry it took me so long.)

@alltom alltom closed this as completed Feb 10, 2014
@ackalker
Copy link
Author

Thanks :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants