0

I have installed Authy on my Nodejs app and it was working great until all of a sudden I get these big err messages coming from inside the plugin. I looks to me like it's missing the copy module, but npm install copy npm update copy did not help.

[TypeError: Object function (comparer) {
for(var i=0; i < this.length; i++) {
    if(comparer(this[i])) return true;
}
return false;
} has no method 'copy']
TypeError: Object function (comparer) {
for(var i=0; i < this.length; i++) {
    if(comparer(this[i])) return true;
}
return false;
} has no method 'copy'
at IncomingMessage.<anonymous> (/home/.../node_modules/authy-node/authy.js:166:13)
at IncomingMessage.EventEmitter.emit (events.js:117:20)
at _stream_readable.js:920:16
at args.(anonymous function)     (/home/.../node_modules/nodetime/lib/core/proxy.js:131:20)
at process._tickCallback (node.js:415:13)

Is it possible copy is not being installed correctly...?

$ npm install copy
npm WARN package.json copy@0.0.1 No repository field.
npm WARN package.json eyes@0.1.8 No repository field.
npm http GET http://registry.npmjs.org/copy
npm http 304 http://registry.npmjs.org/copy
copy@0.0.1 node_modules/copy
S. A.
  • 3,714
  • 2
  • 20
  • 31
Liam Hogan
  • 324
  • 4
  • 13
  • Did you try removing the node_modules folder, updating your package.json and using `npm install` to reinstall everything locally? – JuJoDi Apr 29 '14 at 00:09

1 Answers1

0

Update

Authy has merged my pull request and updated the npm package. This scenario above should now work even if the Array prototype has been extended.

Original Answer

This has nothing to do with a copy module. Based on the source, this is actually due to two separate instances of bad practices within javascript. The first is the due to authy using a for .. in loop to iterate over an array literal. This is a bad thing, as proven by the exception which was thrown. They should have used the standard for loop based on the data.length. I've submitted a pull request to the repo which will fix this issue in the authy module.

So why was the exception thrown? This leads us to the second bad practice. You shouldn't extend the native objects in javascript! Someone somewhere (maybe in your code, maybe in another module) has extended the Array prototype. Based on the function shown in the exception:

function (comparer) {
  for(var i=0; i < this.length; i++) {
    if(comparer(this[i])) return true;
  }
  return false;
}

It looks like someone has extended Array with an inArray as described here: Array.push() if does not exist?

If you can find the code that is doing that and remove it, authy should start working again.

Community
  • 1
  • 1
Timothy Strimple
  • 22,920
  • 6
  • 69
  • 76
  • That's a very useful and well put together answer. I have made some changes to my code like you mentioned and reinstalled node-authy.. and... it's back to work! Thank you – Liam Hogan Apr 29 '14 at 02:52