Minimal reproduction:
function run() {
return new Promise(function(resolve, reject) {
var all = Promise.all(Promise.resolve())
resolve(all) // error occurs on this line
})
}
run().catch(function(err) {
console.log(err.stack)
})
Expected output: nothing
Actual output:
TypeError: Promise.all is not a function
at Function.all (native)
at project-dir/example-es5.js:3:23
at run (project-dir/example-es5.js:2:10)
at Object.<anonymous> (project-dir/example-es5.js:8:1)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Function.Module.runMain (module.js:447:10)
at startup (node.js:141:18)
Ah, that's actually a V8 bug. Going to report it there.
This should be an error as all
expects array as an argument. Error message is incorrect, though
Oops, you're right) Sorry for the hassle.
As noted on @skozin's v8 bug, the error message is fixed in https://chromium.googlesource.com/v8/v8/+/a6ed24d61c597c0e78d2d1c830d86ce33e09153, it may be possible to pull this into the affected Node versions, if it's a problem for users.
+1 for pulling this into the affected node versions -- was very confusing for me
Ran into this one when showing a coworker how to use lazy.js with Promise.all today, I was very confused for a minute. I would appreciate getting a better error message in LTS.
+1 for pulling this into affected node versions - thanks.
+1 The same here, when using object instead of an array. was confused for a while. Worked perfectly in chrome though.
The message is still remain Promise.all is not a function
in v8.1.4 when not passing array param...
@namnm Can't reproduce:
> Promise.all()
Promise {
<rejected> TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
at Function.all (native)
at repl:1:9
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:433:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:278:10),
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> (node:24668) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'Symbol(Symbol.iterator)' of undefined
(node:24668) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
> Promise.all(Promise.resolve())
Promise {
<rejected> TypeError: undefined is not a function
at Function.all (native)
at repl:1:9
at ContextifyScript.Script.runInThisContext (vm.js:44:33)
at REPLServer.defaultEval (repl.js:239:29)
at bound (domain.js:301:14)
at REPLServer.runBound [as eval] (domain.js:314:12)
at REPLServer.onLine (repl.js:433:10)
at emitOne (events.js:120:20)
at REPLServer.emit (events.js:210:7)
at REPLServer.Interface._onLine (readline.js:278:10),
domain:
Domain {
domain: null,
_events: { error: [Function: debugDomainError] },
_eventsCount: 1,
_maxListeners: undefined,
members: [] } }
> (node:24668) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: undefined is not a function
@TimothyGu Sorry, I think the error I faced is another one. My case is that I forgot to put the promises inside an array. Here is the source code and output:
const promise1 = Promise.resolve(1)
const promise2 = Promise.resolve(2)
// It's supposed to be Promise.all([promise1, promise2])
// but I forgot to put the brackets
Promise.all(promise1, promise2)
.then(([v1, v2]) => {
console.log(v1 === 1 && v2 === 2)
}).catch((err) => {
console.log(err)
})
TypeError: undefined is not a function
at Function.all (native)
at Object.<anonymous> (/Users/nnm/ws/test-promise.js:4:9)
at Module._compile (module.js:569:30)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:503:32)
at tryModuleLoad (module.js:466:12)
at Function.Module._load (module.js:458:3)
at Function.Module.runMain (module.js:605:10)
at startup (bootstrap_node.js:158:16)
at bootstrap_node.js:575:3
The message is correct here. Promise.all
is trying to call promise1[Symbol.iterator]()
which is exactly what it's supposed to do, only to find out that promise1[Symbol.iterator]
is undefined
. Note, the original issue is Promise.all is not a function
not undefined is not a function
.
Thank you. Sorry for my wrong report.
@namnm No problem, glad to be of help.
@gsathya has been working on improving these "not iterable" errors. Not sure if the recent progress has affected Promise.all or not, though
https://bugs.chromium.org/p/v8/issues/detail?id=6522 is the tracking bug for this.
Most helpful comment
This should be an error as
all
expects array as an argument. Error message is incorrect, though