npm list co
[ ]
 

Симптомы:
При npm install sqlite3 вывавливается

node-pre-gyp install --fallback-to-build

Лечение:

apt-get install make g++
[ ]
 

Folded:

instances_counter = 0
module.exports = ( -> __class = (-> __args = Array.prototype.slice.call(arguments); if @ instanceof __class then @constructor?.apply(@,__args);@ else new (Function.prototype.bind.apply(__class,[null].concat(__args)))); __class.prototype = @; __class).apply

  constructor_not_required_anymore: (@param1,@param2) ->
    console.log "cnstar"
    @id = ++instances_counter

  render: ->
    console.log @,instances_counter,@ instanceof module.exports

Unfolded:

instances_counter = 0
module.exports = (
  -> 
    __class = (-> 
      __args = Array.prototype.slice.call(arguments)
      if @ instanceof __class 
        @constructor?.apply(@,__args);@
      else 
        new (Function.prototype.bind.apply(__class,[null].concat(__args)))
    );
    __class.prototype = @;
    __class).apply

  constructor_not_required_anymore: (@param1,@param2) ->
    console.log "cnstar"
    @id = ++instances_counter

  render: ->
    console.log @,instances_counter,@ instanceof module.exports
[ ]
 

Folded:

instances_counter = 0
module.exports = (-> __constructor = (-> if @ instanceof __constructor then @constructor.apply(@,Array.prototype.slice.call(arguments)) else new (Function.prototype.bind.apply(__constructor,[null].concat(Array.prototype.slice.call(arguments))))); __constructor.prototype = @; __constructor).apply

  constructor: (@param1,@param2) ->
    console.log "cnstar"
    @id = ++instances_counter

  render: ->
    console.log @,instances_counter,@ instanceof module.exports

Unfolded:

instances_counter = 0
module.exports = (
  -> 
    __constructor = (-> 
      __args = Array.prototype.slice.call(arguments)
      if @ instanceof __constructor 
        @constructor.apply(@,__args) 
      else 
        new (Function.prototype.bind.apply(__constructor,[null].concat(__args)))
    );
    __constructor.prototype = @;
    __constructor).apply

  constructor: (@param1,@param2) ->
    console.log "cnstar"
    @id = ++instances_counter

  render: ->
    console.log @,instances_counter,@ instanceof module.exports

Testing:

Class2 = require './class2'

a = Class2('a1','a2')
b = new Class2('b1','b2')
a.render()
b.render()
console.log a instanceof Class2
console.log b instanceof Class2

Output:

$ coffee class3.coffee 
cnstar
cnstar
{ param1: 'a1', param2: 'a2', id: 1 } 2 true
{ param1: 'b1', param2: 'b2', id: 2 } 2 true
true
true
[ ]
 

Ошибка:

На сервере установлен nvm, при подключении через ssh он не загружается.

Причины:

При входе через ssh вместо .bashrc всегда запускается .bash_profile, а загрузчик nvm прописывается себя в .bashrc

Решение:

Создать на сервере файл ~/.bash_profile с командой загрузки bashrc:

if [ -f ~/.bashrc ]; then
  . ~/.bashrc
fi

Дополнительно:

Эта параша может продолжать писать, что node not found, в этом случае надо сделать живительный nvm use default

[ ]
 

Ошибка:

При работе с transform - стримом выводилась ошибка

$ coffee urlsgenerator.coffee|coffee splitter-case.coffee 
/home/space1000/tst/streams/splitter-case.coffee:8
      this.push(chunk.toString());
           ^
TypeError: undefined is not a function
  at [object Object]._onTimeout (/home/space1000/tst/streams/splitter-case.coffee:5:9)
  at Timer.listOnTimeout (timers.js:110:15)

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: write EPIPE
  at exports._errnoException (util.js:746:11)
  at WriteWrap.afterWrite (net.js:766:14)

Причина:

Ошибка не связана с потоками или стримингом. Ошибка была простой ошибкой, которую выкидывает интерпретатор в процессе работы кода. В данном случае она находится в самом верху:

/home/space1000/tst/streams/splitter-case.coffee:8
      this.push(chunk.toString());
           ^
TypeError: undefined is not a function

Однако, ввиду того, что в stdout уже пайпнут вышеупомянутый трасформ-стрим, обычный вывод ошибок, который в ноде идёт не в stderr, а в stdout (интересно, можно ли это изменить?), да и вообще вывод в stdout чего угодно уже считается тяжким преступлением и карается выбрасыванием Error: write EPIPE, что и придаёт обычной с виду ошибке такую мудацкую нечитаемую форму, которая заставляет пенять на какие-то скрытые баги в коде самой ноды или coffeescript или вообще хуй знает чего.

Пример:

urlsgenerator.coffee

rs = (require 'stream').Readable()
rs.drained = false

outputData = 
[
  "http://ya.ru "
  "http://goo"
  "gle.com\n"
  "http://bing.com "
  "http://y"
  "aho"
  "o.com\n"
  "http://rambler.ru"
]

intervalId = setInterval(
  ->
    if rs.drained
      if outputData.length isnt 0
        rs.drained = false
        #console.error(outputData.shift())
        rs.push(outputData.shift())
      else
        rs.push(null)
        clearInterval(intervalId)
  ,250
)

rs._read = ->
  rs.drained = true

rs.pipe(process.stdout)

splitter-case.coffee

ts = new (require 'stream').Transform()
ts._transform = (chunk, encoding, done) ->
  setTimeout(
    ->
      @.push(chunk.toString())
      done()
    ,1000
  )
 
process.stdin.pipe(ts)
ts.pipe(process.stdout)

Вывод:

$ coffee urlsgenerator.coffee|coffee splitter-case.coffee 
/home/space1000/tst/streams/splitter-case.coffee:8
      this.push(chunk.toString());
           ^
TypeError: undefined is not a function
  at [object Object]._onTimeout (/home/space1000/tst/streams/splitter-case.coffee:5:9)
  at Timer.listOnTimeout (timers.js:110:15)

events.js:85
      throw er; // Unhandled 'error' event
            ^
Error: write EPIPE
  at exports._errnoException (util.js:746:11)
  at WriteWrap.afterWrite (net.js:766:14)

Обновлённый код splitter-case с исправленной (типичной) ошибкой:

ts = new (require 'stream').Transform()
ts._transform = (chunk, encoding, done) ->
  setTimeout(
    =>
      @.push(chunk.toString())
      done()
    ,1000
  )
 
process.stdin.pipe(ts)
ts.pipe(process.stdout)

Результат выполнения той же операции:

$ coffee urlsgenerator.coffee|coffee splitter-case.coffee 
http://ya.ru http://google.com
http://bing.com http://yahoo.com
http://rambler.ru

[ ]
 

Ошибка:
После запуска coffee всегда печатает надпись

Running node v0.11.13

Возможная причина проблемы:

Всё запускается через жопу NVM:

$ cat .bashrc|grep "alias coffee"
alias coffee='nvm run 0.11.13 --harmony /usr/local/bin/coffee'
$ nvm run 0.11.13 /usr/local/bin/coffee 123.coffee
Running node v0.11.13
123

Решение:

Убедиться, что bin/coffee запускается напрямую, а не какими-то окольными путями.

$ /usr/local/bin/coffee 123.coffee
123
[ ]
 

Код:

process.stdout.push "123"

Ошибка:

Running node v0.11.13
_stream_readable.js:445
    stream.read(0);
           ^
TypeError: object is not a function
  at maybeReadMore_ (_stream_readable.js:445:12)
  at _stream_readable.js:435:7
  at process._tickCallback (node.js:343:11)
  at Function.Module.runMain (module.js:492:11)
  at startup (node.js:124:16)
  at node.js:807:3

Причина:

push() предназначен для Readable потоков. Для Writable используется write()

[ ]
 

Это

wait1sec = (done) ->
  setTimeout(
    -> 
      console.log("1 sec passed")
      done(null,"1sec")
    ,
    1000
  )
[ ]