maxtaco / coffee-script

IcedCoffeeScript
http://maxtaco.github.com/coffee-script
MIT License
726 stars 58 forks source link

Errors with sample code on ICS site & server-side (node) #26

Closed demark closed 12 years ago

demark commented 12 years ago

Hello, maybe smth is broken in current version but i cant run ICS without error on your tutorial site nor on server-side (node)

ICS site (client-side)

For example, go to http://maxtaco.github.com/coffee-script/ , click on Try It and paste sample code

for i in [0..10]
  await setTimeout(defer(), 100)
  console.log "hello"

Run and watch console: after executing (chrome 17.0.963.79 m) we've got an error:

Uncaught TypeError: undefined is not a function
_while
_continue
_while
require../iced.a.generator.d.Deferrals.b._call  coffee-script.js:8
require../iced.a.generator.d.Deferrals.b._fulfill   coffee-script.js:8
require../iced.a.generator.a.makeDeferReturn.j  coffee-script.js:8

Now about server-side

My conf is: Ubuntu 10.04, npm 1.1.4, nodejs v0.6.12, coffee-script 1.2.0 (-g), iced-coffee-script 1.2.0s (-g)

The same sample code snippet above works (iced -I inline iced.coffee) with error in the end:

timers.js:96
            if (!process.listeners('uncaughtException').length) throw e;
                                                                      ^
TypeError: undefined is not a function
    at /home/ubuntu/app1/iced.coffee:53:14
    at /home/ubuntu/app1/iced.coffee:49:14
    at _Class.continuation (/home/ubuntu/app1/iced.coffee:64:16)
    at _Class._fulfill (/home/ubuntu/app1/iced.coffee:16:40)
    at Object._onTimeout (/home/ubuntu/app1/iced.coffee:30:24)
    at Timer.ontimeout (timers.js:94:19)

If i'm trying to run in node mode (iced iced.coffee) with adding to the top of src iced = require('iced-coffee-script').iced, i've got this err:

Error: Cannot find module 'iced-coffee-script'
    at Function._resolveFilename (module.js:332:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at Object.<anonymous> (/home/ubuntu/app1/iced.coffee:5:10)
    at Object.<anonymous> (/home/ubuntu/app1/iced.coffee:37:4)
    at Module._compile (module.js:441:26)
    at Object.run (/usr/lib/node_modules/iced-coffee-script/lib/coffee-script/coffee-script.js:92:25)
    at /usr/lib/node_modules/iced-coffee-script/lib/coffee-script/command.js:152:29
    at /usr/lib/node_modules/iced-coffee-script/lib/coffee-script/command.js:127:18
maxtaco commented 12 years ago

Nice catch, I'll look into it.

maxtaco commented 12 years ago

Should be fixed in 1.2.0t

demark commented 12 years ago

Okay, iced -I inline mode bug fixed. But on node mode still not

iced = require('iced-coffee-script').iced

for i in [0..5]
    await setTimeout defer(), 1000
    console.log i

Still throws the same err

maxtaco commented 12 years ago

You sure you're all up-to-date and your paths are set correctly? For me it just worked with 1.2.0t but failed with 1.2.0s

maxtaco commented 12 years ago

....And sadly there's not a good way to add a regtest here...

demark commented 12 years ago

You sure you're all up-to-date and your paths are set correctly?

Hmm, i've recently installed ubuntu 10.04 & coffee-script & iced-coffee-script packages installed globally using npm

sudo npm install coffee-script -g
sudo npm install iced-coffee-script -g

What file i should look to check correct paths?

maxtaco commented 12 years ago

Can you do this for me? iced --print test.coffee and paste in the result? Here test.coffee is that little demo script that you have.

maxtaco commented 12 years ago

Also, what does iced --version output?

demark commented 12 years ago

IcedCoffeeScript version 1.2.0t

&&


(function() {
  var i, iced, __iced_deferrals, __iced_k, __iced_k_noop, _i, _next, _while,
    _this = this;

  iced = require('iced-coffee-script').iced;
  __iced_k = __iced_k_noop = function() {};

  i = 0;
  _while = function(__iced_k) {
    var _break, _continue;
    _break = __iced_k;
    _continue = function() {
      ++i;
      return _while(__iced_k);
    };
    _next = _continue;
    if (!(i <= 5)) {
      return _break();
    } else {
      (function(__iced_k) {
        __iced_deferrals = new iced.Deferrals(__iced_k, {
          filename: "iced.coffee"
        });
        setTimeout(__iced_deferrals.defer({
          lineno: 3
        }), 1000);
        __iced_deferrals._fulfill();
      })(function() {
        return _next(console.log(i));
      });
    }
  };
  _while(__iced_k);

}).call(this);
maxtaco commented 12 years ago

Ah, OK, I see what's going on, my bad. It's that your node runtime can't find the iced libraries (and the bug you reported is now fixed with -I node for me). Hmm, how we can debug this. I assume when you do require('iced-coffee-script') from your node REPL that it also fails? Can you npm install another package you don't have and see if you can require those modules? Also, what version of node are you running? node --version? It could be 10.04 ubuntu has an old version of node.js

demark commented 12 years ago

Hmm, smth with paths seems to be broken. I've just updated node to 0.6.13, npm to 1.1.10, reinstalled iced-coffee-script

sudo npm remove iced-coffee-script -g
sudo npm install iced-coffee-script -g

and in REPL mode it still fails :(

var iced = require('iced-coffee-script').iced

Error: Cannot find module 'iced-coffee-script'
    at Function._resolveFilename (module.js:332:11)
    at Function._load (module.js:279:25)
    at Module.require (module.js:354:17)
    at require (module.js:370:17)
    at repl:1:12
    at REPLServer.eval (repl.js:80:21)
    at repl.js:190:20
    at REPLServer.eval (repl.js:87:5)
    at Interface.<anonymous> (repl.js:182:12)
    at Interface.emit (events.js:67:17)

Where i need to digg to solve issue with paths?

demark commented 12 years ago

Okay, i've just tried to run in REPL mode on another machine (ubuntu 11.10 x86_64, node v0.6.13, npm 1.1.10, coffee-script 1.2.0, iced-coffee-script 1.2.0t)

ICS was installed by npm: npm install iced-coffee-script -g

and i've got the same error:

mark@db:~$ iced
iced> iced = require('iced-coffee-script').iced
Error: Cannot find module 'iced-coffee-script'
    at Function._resolveFilename (module.js:332:11)
    at Function._load (module.js:279:25)
    at /home/mark/.nvm/v0.6.13/lib/node_modules/iced-coffee-script/lib/coffee-script/coffee-script.js:126:25
    at evalmachine.<anonymous>:3:13
    at Object.eval (/home/mark/.nvm/v0.6.13/lib/node_modules/iced-coffee-script/lib/coffee-script/coffee-script.js:149:17)
    at Interface.<anonymous> (/home/mark/.nvm/v0.6.13/lib/node_modules/iced-coffee-script/lib/coffee-script/repl.js:117:40)
    at Interface.emit (events.js:67:17)
    at Interface._onLine (readline.js:162:10)
    at Interface._line (readline.js:426:8)
    at Interface._ttyWrite (readline.js:603:14)

Any ideas?

maxtaco commented 12 years ago

You need to set the environment variable NODE_PATH. If you're using bash as your shell, then add this line to your ~/.bashrc:

export NODE_PATH=/usr/local/lib/node_modules

and type source ~/.bashrc.

Let me know if this fixes it.

Or you can just try it as a one-off from the command line:

 export NODE_PATH=/usr/local/lib/node_modules

In general, this is a bug with your node configuration. You probably can't get any module to work via NPM, I'm guessing, unless you have your path set.

demark commented 12 years ago

Fuh, export NODE_PATH=/usr/lib/node_modules made it work (without /local/). Big thanks, Maxwell :)

One more thing: To run globally: sudo npm install -dg iced-coffee-script <- attention to -d flag To run local: npm install iced-coffee-script -> ~/node_modules/.bin/iced %filenname%.coffee