question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'all' of undefined

See original GitHub issue

Environment

Knex version: 0.19.1 Database + version: PostgreSQL 11.4 OS: Antergos (Arch Linux)

Bug

  1. Explain what kind of behaviour you are getting and how you think it should do I wanted to run a migration in order to add a new column to a table. I have already added columns to a table successfully this way:
exports.up = function (knex, Promise) {
    return Promise.all([
        knex.schema.table("myTable", table => {
            table.string("myColumn");
        })
    ]);
};

exports.down = function (knex, Promise) {
    return Promise.all([
        knex.schema.table("myTable", table => {
            table.dropColumn("myColumn");
        })
    ]);
};

This time knex has thrown an error (see below). I’ve managed to run the migration successfully this way:

exports.up = function (knex, Promise) {
    return knex.schema.table('myTable', function (table) {
        table.string('myColumn');

    })
};

exports.down = function (knex, Promise) {
    return knex.schema.table('myTable', function (table) {
        table.dropColumn('myColumn');
    })
};

but I found it weird that suddenly the first method suddenly does not work.

  1. Error message
TypeError: Cannot read property 'all' of undefined
    at Object.exports.up (/home/user/databases/config/migrations/20190727133408_add_columns_myTable.js:2:20)
    at Object.current.then (/home/user/node_modules/knex/lib/migrate/Migrator.js:454:40)
    at Object.tryCatcher (/home/user/node_modules/knex/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:517:31)
    at Promise._settlePromise (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:574:18)
    at Promise._settlePromiseCtx (/home/user/node_modules/knex/node_modules/bluebird/js/release/promise.js:611:10)
    at _drainQueueStep (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:142:12)
    at _drainQueue (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/home/user/node_modules/knex/node_modules/bluebird/js/release/async.js:17:14)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
  1. Reduced test code, for example in https://npm.runkit.com/knex or if it needs real database connection to MySQL or PostgreSQL, then single file example which initializes needed data and demonstrates the problem.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

29reactions
ricardogracacommented, Jul 27, 2019

The second argument Promise was removed in version 0.18.4: https://github.com/tgriesser/knex/commit/2ccaf3d7244f68bc3553e35ef49a2a2a53322496

If you want to use Promise.all it is available natively in Node.js since version 0.12, so just remove the second argument to the up and down functions:

exports.down = function (knex) {
  return Promise.all([])
}
2reactions
elhigucommented, Feb 12, 2020

@Isanderthul instead of removing second argument, you could have as well done

exports.down = function(knex, promise) {
    return (undefined || Promise).resolve();
};
Read more comments on GitHub >

github_iconTop Results From Across the Web

Uncaught TypeError: Cannot read property of undefined In
JavaScript TypeError is thrown when an operand or argument passed to a function is incompatible with the type expected by that operator or...
Read more >
[SOLVED] Cannot Read Property of Undefined in JavaScript
The “cannot read property of undefined” error occurs when you attempt to access a property or method of a variable that is undefined...
Read more >
Failed: Cannot read property 'all' of undefined - Stack Overflow
In version 4.0.0, the function protractor.promise.all is no longer present in the protractor.promise namespace:.
Read more >
Uncaught TypeError : Cannot read properties of undefined
The root cause of the error is that the declared variable doesn't have any value, so by default, JavaScript treats all variables as...
Read more >
How to Avoid the Infamous "Cannot read properties of ... - Bitovi
Interpreting undefined or null as subtypes of all other types can lead to runtime problems. For example, if you try to get the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found