diff --git a/UPGRADING.md b/UPGRADING.md index cc4d709c70..5916e5a80b 100644 --- a/UPGRADING.md +++ b/UPGRADING.md @@ -4,7 +4,8 @@ * MSSQL: DB versions older than 2008 are no longer supported, make sure to update your DB; * PostgreSQL|MySQL: it is recommended to use options object for `table.datetime` and `table.timestamp` methods instead of argument options. See documentation for these methods for more details; -* Node 6: There are known issues with duplicate event listeners when using knex.js with Node 6 (resulting in MaxListenersExceededWarning under certain use-cases (such as reusing single knex instance to run migrations or seeds multiple times)). Please upgrade to Node 8+ as soon as possible (knex 0.17.0 will be dropping Node 6 support altogether). +* Node 6: There are known issues with duplicate event listeners when using knex.js with Node.js 6 (resulting in MaxListenersExceededWarning under certain use-cases (such as reusing single knex instance to run migrations or seeds multiple times)). Please upgrade to Node.js 8+ as soon as possible (knex 0.17.0 will be dropping Node.js 6 support altogether); +* Node 6: Please add '@babel/polyfill' production dependency to the project when using Node.js 6 (it will be loaded by knex automatically). ### Upgrading to version 0.15.0+ diff --git a/knex.js b/knex.js index 6b0c296918..1d68216f1e 100644 --- a/knex.js +++ b/knex.js @@ -9,13 +9,19 @@ const { isNode6 } = require('./lib/util/version-helper'); // Should be safe to remove after support for Node.js 6 is dropped if (isNode6()) { - const oldPromise = global.Promise; + try { + const oldPromise = global.Promise; - require('@babel/polyfill'); + require('@babel/polyfill'); - // Preserve any Promise overrides set globally prior to importing knex - if (oldPromise) { - global.Promise = oldPromise; + // Preserve any Promise overrides set globally prior to importing knex + if (oldPromise) { + global.Promise = oldPromise; + } + } catch (e) { + throw new Error( + `You are using Node.js 6. Please consider upgrading to Node.js 8+ or add '@babel/polyfill' dependency to the project (knex will automatically load it).` + ); } } diff --git a/package.json b/package.json index 348c532467..4c765cf252 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,6 @@ "node": ">=6" }, "dependencies": { - "@babel/polyfill": "^7.2.5", "@types/bluebird": "^3.5.25", "bluebird": "^3.5.3", "colorette": "1.0.7", @@ -35,6 +34,7 @@ "devDependencies": { "@babel/cli": "^7.2.3", "@babel/core": "^7.2.2", + "@babel/polyfill": "^7.2.5", "@babel/preset-env": "^7.3.1", "@types/node": "*", "JSONStream": "^1.3.5", diff --git a/src/migrate/sources/fs-migrations.js b/src/migrate/sources/fs-migrations.js index 7e3fc2b4c2..8dc9050aa1 100644 --- a/src/migrate/sources/fs-migrations.js +++ b/src/migrate/sources/fs-migrations.js @@ -3,7 +3,8 @@ import path from 'path'; import Promise from 'bluebird'; import { sortBy, filter } from 'lodash'; -const readDirAsync = (path) => Promise.promisify(fs.readdir, { context: fs })(path); +const readDirAsync = (path) => + Promise.promisify(fs.readdir, { context: fs })(path); export const DEFAULT_LOAD_EXTENSIONS = Object.freeze([ '.co',