"is not a function" error points to the wrong code point
Hi! Stumbled upon this minor issue where an "is not a function" error points to the wrong code point.
Test case:
// config.js
module.exports = function(path) {
var config = require(path ? path.resolve(process.cwd(), path) : '../config');
return config;
};
// index.js
var config = require('./config')('config');
Result:
config.js:4
var config = require(path ? path.resolve(process.cwd(), path) : '../config
^
TypeError: process.cwd is not a function
at module.exports (config.js:4:54)
Expected (moved the arrow):
var config = require(path ? path.resolve(process.cwd(), path) : '../config
^
Tested with:
- nodejs v0.12.5
- iojs v2.3.1
It really is a minor issue, but can be confusing when debugging.
The error is that process.cwd is not a function and the arrow points at process.cwd, what is the problem?
console.log(process.cwd); returns [Function: cwd]
console.log(path.resolve); returns undefined
Since the message says process.cwd is not a function then it's either not a function or the bug is in v8.
Probably an issue with v8, it sends the wrong error message in ternaries:
> var v = 'string';
undefined
> true ? v.resolve(process.cwd()) : false
TypeError: process.cwd is not a function
at repl:1:26
...
> v.resolve(process.cwd())
TypeError: v.resolve is not a function
at repl:1:3
...
It seems correct in 4.5:
V8 version 4.5.0 (candidate) [console: dumb]
d8> var process = { cwd: function(){} }
undefined
d8> var v = 'string';
undefined
d8> true ? v.resolve(process.cwd()) : false
(d8):1: TypeError: v.resolve is not a function
true ? v.resolve(process.cwd()) : false
^
TypeError: v.resolve is not a function
at (d8):1:10
d8> v.resolve(process.cwd())
(d8):1: TypeError: v.resolve is not a function
v.resolve(process.cwd())
^
TypeError: v.resolve is not a function
at (d8):1:3
Not sure if this is the same issue
Seems to work with the v8 upgrade in 3.0.0:
brendanashworth in ~ $ node -v
v3.0.0
brendanashworth in ~ $ node
> var v = 'string'
undefined
> true ? v.resolve(process.cwd()) : false
TypeError: v.resolve is not a function
at repl:1:10
...
brendanashworth in ~ $ node -v
v2.3.1
brendanashworth in ~ $ node
> var v = 'string'
undefined
> true ? v.resolve(process.cwd()) : false
TypeError: process.cwd is not a function
at repl:1:26
...
Thanks for the bug report! I'll close this, please reopen / comment if it comes back.