Why does my Knex migration fail on Heroku but not locally? - heroku

I am trying to deploy my first React app on Heroku and everything seems to work fine until I get to the migrations. My Knex migration works fine locally but when I try to run it on Heroku the migration fails.
Since it works fine when run on my local machine and this is my first time trying to deploy anything, I'm not sure how to debug this.
Here is my migration code:
exports.up = function(knex, Promise) {
return Promise.all([
// USERS TABLE
knex.schema.createTable('users', t => {
t.uuid('id')
.primary()
.unique()
.notNullable();
t.string('name').notNullable();
t.string('email')
.unique()
.notNullable();
t.string('password').notNullable();
t.timestamp('joined', { useTz: false }).notNullable();
t.text('website');
t.string('github');
t.string('twitter');
t.text('avatar');
t.boolean('is_admin')
.defaultTo(false)
.notNullable();
}),
// INSTRUCTORS TABLE
knex.schema.createTable('instructors', t => {
t.uuid('id')
.primary()
.unique()
.notNullable();
t.string('name')
.unique()
.notNullable();
t.timestamp('created', { useTz: false }).notNullable();
t.text('website');
t.string('github');
t.string('twitter');
t.text('avatar');
}),
// TUTORIALS TABLE
knex.schema.createTable('tutorials', t => {
t.string('id')
.primary()
.unique()
.notNullable();
t.uuid('user_id').notNullable();
t.uuid('instructor_id');
t.string('instructor_name');
t.string('title').notNullable();
t.text('url')
.unique()
.notNullable();
t.timestamp('date', { useTz: false }).notNullable();
t.enum('cost', ['free', 'paid']).notNullable();
t.enum('medium', ['article', 'video']).notNullable();
t.enum('difficulty', ['beginner', 'advanced']).notNullable();
t.specificType('categories', 'text ARRAY').notNullable();
}),
// COMMENTS TABLE
knex.schema.createTable('comments', t => {
t.string('id')
.primary()
.unique()
.notNullable();
t.uuid('user_id').notNullable();
t.string('tutorial_id').notNullable();
t.text('body').notNullable();
t.timestamp('date', { useTz: false }).notNullable();
}),
knex.schema.createTable('tutorial_votes', t => {
t.uuid('id')
.primary()
.unique()
.notNullable();
t.string('tutorial_id').notNullable();
t.uuid('user_id').notNullable();
t.smallint('vote_value');
}),
knex.schema.createTable('comment_votes', t => {
t.uuid('id')
.primary()
.unique()
.notNullable();
t.string('comment_id').notNullable();
t.uuid('user_id').notNullable();
t.smallint('vote_value');
}),
knex.schema.createTable('favorites', t => {
t.uuid('id')
.primary()
.unique()
.notNullable();
t.string('tutorial_id').notNullable();
t.uuid('user_id').notNullable();
t.timestamp('date', { useTz: false }).notNullable();
})
]);
console.log('Tables created successfully');
};
exports.down = function(knex, Promise) {
return Promise.all([
knex.schema.dropTable('users'),
knex.schema.dropTable('instructors'),
knex.schema.dropTable('tutorials'),
knex.schema.dropTable('comments'),
knex.schema.dropTable('tutorial_votes'),
knex.schema.dropTable('comment_votes'),
knex.schema.dropTable('favorites')
]);
console.log('Tables dropped');
};
And here is the error I get:
remote: migration file "20190731184441_setup.js" failed
remote: migration failed with error: Cannot read property 'all' of undefined
remote: TypeError: Cannot read property 'all' of undefined
remote: at Object.exports.up (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/db/migrations/20190731184441_setup.js:2:18)
remote: at Object.<anonymous> (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/lib/migrate/Migrator.js:503:40)
remote: at Object.tryCatcher (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/util.js:16:23)
remote: at Promise._settlePromiseFromHandler (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/promise.js:547:31)
remote: at Promise._settlePromise (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/promise.js:604:18)
remote: at Promise._settlePromiseCtx (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/promise.js:641:10)
remote: at _drainQueueStep (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/async.js:97:12)
remote: at _drainQueue (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/async.js:86:9)
remote: at Async._drainQueues (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/async.js:102:5)
remote: at Immediate.Async.drainQueues [as _onImmediate] (/tmp/build_7917ecdef592ca80a65bfdee9b4e67c6/server/node_modules/knex/node_modules/bluebird/js/release/async.js:15:14)
remote: at processImmediate (internal/timers.js:439:21)

I think this is likely to be a version mismatch between what you have locally and what Heroku has installed. If your semver specification was quite permissive, that would allow Heroku to install a more recent version, and perhaps you've been developing against the local one for quite awhile.
The reason I suspect this: Knex switched to native promises in version 0.18.0, which means that migrations are no longer passed a Bluebird Promise. That parameter doesn't exist anymore, hence your error.

Fixed by removing Promise from exports.up = function(knex, Promise) & exports.down = function(knex, Promise)

Related

Microsoft Teams TASK module SSO is returning `Definition not found` error

We are getting Definition not found error while calling msTeams.authentication.getAuthToken in #microsoft/teams-js from the task module.
#microsoft/teams-js version - 1.7.0 and 1.11.0
Environment - Desktop and Mobile
return new Observable<any>(subscriber => {
this.teamsService.authentication.getAuthToken({
resources: ['https://graph.microsoft.com/openid',
'https://graph.microsoft.com/user.read.all',
'https://graph.microsoft.com/group.read.all',
'https://graph.microsoft.com/groupmember.read.all'],
successCallback: clientToken => {
subscriber.next({ clientToken, type: this.authType });
subscriber.complete();
},
failureCallback: reason => {
subscriber.error(reason);
}
});
});

getting error: [semantic-release] › ✖ EPLUGINSCONF The `plugins` configuration is invalid

I am very new to semantic release so not sure I can exec multiple #semantic-release/exec at a time in a single .releaserc file.
Please let me know if this is feasible, if yes then what is my mistake.
I am getting error:
[7:30:34 AM] [semantic-release] › ℹ Running semantic-release version 17.4.7
2021-09-03T07:30:34.784Z semantic-release:config load config from: /home/runner/work/docker-loki/docker-loki/.releaserc
2021-09-03T07:30:34.793Z semantic-release:config options values: {
branches: [ 'main', { name: 'pre', prerelease: 'beta' } ],
repositoryUrl: 'https://github.com/screencloud/docker-loki',
tagFormat: 'v${version}',
plugins: [
'#semantic-release/commit-analyzer',
'#semantic-release/release-notes-generator',
'#semantic-release/github',
[ [Array] ]
],
_: [],
debug: true,
'$0': '/usr/local/bin/semantic-release'
}
[7:30:34 AM] [semantic-release] › ✖ EPLUGINSCONF The `plugins` configuration is invalid.
The plugins (https://github.com/semantic-release/semantic-release/blob/master/docs/usage/configuration.md#plugins) option must be an array of plugin definions. A plugin definition is an npm module name, optionally wrapped in an array with an object.
The invalid configuration is [ [ '#semantic-release/exec', { prepareCmd1: './scripts/semantic-release/prepareCmd-loki.sh v${nextRelease.version}', publishCmd1: './scripts/semantic-release/publishCmd-loki.sh v${nextRelease.version}' }, '#semantic-release/exec', { prepareCmd2: './scripts/semantic-release/prepareCmd-grafana.sh v${nextRelease.version}', publishCmd2: './scripts/semantic-release/publishCmd-grafana.sh v${nextRelease.version}' } ] ].
AggregateError:
SemanticReleaseError: The `plugins` configuration is invalid.
at module.exports (/usr/local/lib/node_modules/semantic-release/lib/get-error.js:6:10)
at /usr/local/lib/node_modules/semantic-release/lib/plugins/index.js:34:23
at Array.reduce (<anonymous>)
at module.exports (/usr/local/lib/node_modules/semantic-release/lib/plugins/index.js:14:34)
at module.exports (/usr/local/lib/node_modules/semantic-release/lib/get-config.js:84:35)
at async module.exports (/usr/local/lib/node_modules/semantic-release/index.js:257:32)
at async module.exports (/usr/local/lib/node_modules/semantic-release/cli.js:55:5)
at module.exports (/usr/local/lib/node_modules/semantic-release/lib/plugins/index.js:42:11)
at module.exports (/usr/local/lib/node_modules/semantic-release/lib/get-config.js:84:35)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async module.exports (/usr/local/lib/node_modules/semantic-release/index.js:257:32)
at async module.exports (/usr/local/lib/node_modules/semantic-release/cli.js:55:5)
Error: Process completed with exit code 1.
my .releaserc
{
"branches": [
"main",
{
"name": "pre",
"prerelease": "beta"
}
],
"plugins": [
"#semantic-release/commit-analyzer",
"#semantic-release/release-notes-generator",
"#semantic-release/github",
[ [ '#semantic-release/exec',
{
prepareCmd: './scripts/semantic-release/prepareCmd-loki.sh v${nextRelease.version}',
publishCmd: './scripts/semantic-release/publishCmd-loki.sh v${nextRelease.version}'
},
'#semantic-release/exec',
{
prepareCmd1: './scripts/semantic-release/prepareCmd-grafana.sh v${nextRelease.version}',
publishCmd1: './scripts/semantic-release/publishCmd-grafana.sh v${nextRelease.version}'
}
]
]
],
}

Rollup CommonJS plugin throwing error when importing Sass files in dependencies

I'm using Rollup on a Sapper project found here: https://github.com/darryl-snow/perfect-cookie
Yesterday I ran npm update and since then when I run npm run dev I get the following error:
✗ client
Invalid CSS after "...-features: list": expected expression (e.g. 1px, bold), was ".append($available-"
✗ server
Invalid CSS after "...-features: list": expected expression (e.g. 1px, bold), was ".append($available-"
internal/modules/cjs/loader.js:985
throw err;
^
My rollup config:
import resolve from '#rollup/plugin-node-resolve'
import replace from '#rollup/plugin-replace'
import commonjs from '#rollup/plugin-commonjs'
import svelte from 'rollup-plugin-svelte'
import postcss from 'rollup-plugin-postcss'
import babel from 'rollup-plugin-babel'
import { terser } from 'rollup-plugin-terser'
import config from 'sapper/config/rollup.js'
import pkg from './package.json'
const mode = process.env.NODE_ENV
const dev = mode === 'development'
const legacy = !!process.env.SAPPER_LEGACY_BUILD
const onwarn = (warning, onwarn) =>
(warning.code === 'CIRCULAR_DEPENDENCY' && /[/\\]#sapper[/\\]/.test(warning.message)) || onwarn(warning)
const postcssOptions = () => ({
extensions: ['.scss', '.sass'],
extract: false,
minimize: true,
use: [
[
'sass',
{
includePaths: ['./src/theme', './node_modules'],
},
],
],
})
export default {
client: {
input: config.client.input(),
output: config.client.output(),
plugins: [
replace({
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode),
}),
svelte({
dev,
hydratable: true,
emitCss: true,
}),
resolve({
browser: true,
dedupe: ['svelte'],
}),
commonjs(),
postcss(postcssOptions()),
legacy &&
babel({
extensions: ['.js', '.mjs', '.html', '.svelte'],
runtimeHelpers: true,
exclude: ['node_modules/#babel/**'],
presets: [
[
'#babel/preset-env',
{
targets: '> 0.25%, not dead',
},
],
],
plugins: [
'#babel/plugin-syntax-dynamic-import',
[
'#babel/plugin-transform-runtime',
{
useESModules: true,
},
],
],
}),
!dev &&
terser({
module: true,
}),
],
onwarn,
},
server: {
input: config.server.input(),
output: config.server.output(),
plugins: [
replace({
'process.browser': false,
'process.env.NODE_ENV': JSON.stringify(mode),
}),
svelte({
generate: 'ssr',
dev,
}),
resolve({
dedupe: ['svelte'],
}),
commonjs(),
postcss(postcssOptions()),
],
external: Object.keys(pkg.dependencies).concat(
require('module').builtinModules || Object.keys(process.binding('natives'))
),
onwarn,
},
serviceworker: {
input: config.serviceworker.input(),
output: config.serviceworker.output(),
plugins: [
resolve(),
replace({
'process.browser': true,
'process.env.NODE_ENV': JSON.stringify(mode),
}),
commonjs(),
!dev && terser(),
],
onwarn,
},
}
I've tried rm -rf ./node_modules && npm install but still getting the same error. It looks like commonJS is loading dependencies and finding one where it's expecting CSS but getting Sass... I'm completely new to rollup, any ideas?
You should probably consider installing the latest major version of #rollup/plugin-commonjs. The one you're currently using has a bug with Sapper (which I've encountered while running your repo instead of the one in the question) and it was fixed in the later versions.
After upgrading that, your project seems to start up fine.
While you're at it, upgrade the other major version upgrades, very likely that most of them will go by without errors.

Protractor - jasmine TypeError: cannot read property 'result' of undefined

Recently i encounter an issue below, whenever i try to execute protractor tests remotely.
I receive an error message upon execution:
npm run e2e:remote
> hogs#0.1.22 e2e:remote /home/user/projects/project
> ./node_modules/protractor/bin/protractor e2e/protractor.remote.conf.js
[09:34:07] I/launcher - Running 1 instances of WebDriver
[09:34:07] I/hosted - Using the selenium server at http://localhost:4444/wd/hub
Jasmine started
/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120
return children && children[0].result.status;
^
TypeError: Cannot read property 'result' of undefined
at isAfterAll (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5120:36)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5083:8)
at Suite.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5095:27)
at QueueRunner.onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:5191:28)
at onException (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4310:14)
at handleError (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:4243:11)
at process.onerror (/home/user/projects/project/node_modules/protractor/node_modules/jasmine-core/lib/jasmine-core/jasmine.js:2371:17)
at process.emit (events.js:223:5)
at process.emit (/home/user/projects/project/node_modules/protractor/node_modules/source-map-support/source-map-support.js:439:21)
at process.emit (/home/user/projects/project/node_modules/source-map-support/source-map-support.js:485:21)
Due to the above, i am unable to run tests at all at remote.
my protractor.conf.js:
require('dotenv').config();
const { SpecReporter } = require('jasmine-spec-reporter');
/**
* #type { import("protractor").Config }
*/
exports.config = {
seleniumAddress: process.env.SELENIUM_SERVER_ADDRESS || `http://localhost:4444/wd/hub`,
allScriptsTimeout: 11000,
specs: ['./src/**/*.e2e-spec.ts'],
// directConnect: true,
multiCapabilities: [
{
browserName: 'chrome',
shardTestFiles: false,
maxInstances: 2,
},
//{
// browserName: 'firefox',
//},
],
maxSessions: -1,
baseUrl: process.env.REMOTE_URL || "",
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true,
defaultTimeoutInterval: 30000,
print: function() {},
},
onPrepare() {
process.env.USER_EMAIL = process.env.USER_EMAIL || '';
process.env.USER_PASSWORD = process.env.USER_PASSWORD || '';
require('ts-node').register({
project: 'e2e/tsconfig.json',
});
jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
},
};
Tests run smoothly when i uncomment the directconnect, though in our project we are supposed to run tests through selenium grid, so it is vital that remote runs without it.
Jasmine version is 3.5.0,
Protractor is ver 5.4.3.

Property doesn't exist on type {}

I am trying to get a list of objects from a firebase db using snapshotChanges.
Angular Version: 7.2.0,
Firebase Version: 5.8.1,
RxJS Version: 6.3.3,
AngularFire2: 5.1.1
My code is the following:
this.fbSubs.push(this.db
.collection('availableExercises')
.snapshotChanges()
.pipe(
map(docArray => {
return docArray.map(doc => {
return {
idExercise: doc.payload.doc.id,
name: doc.payload.doc.data().name,
duration: doc.payload.doc.data().duration,
calories: doc.payload.doc.data().calories
};
});
})
)
.subscribe((exercises: Exercise[]) => {
// code...
}, error => {
// code...
}));
When I try to compile this code, I get the following errors:
ERROR in src/app/training/training.service.ts(41,44): error TS2339: Property 'name' does not exist on type '{}'.
src/app/training/training.service.ts(42,48): error TS2339: Property 'duration' does not exist on type '{}'.
src/app/training/training.service.ts(43,48): error TS2339: Property 'calories' does not exist on type '{}'.
I believe the syntax may be outdated from a previous version of RxJS but I can't seem to work out what I need to change.
So I had to slightly change the code around in .pipe.map() to return the data as "Exercise" like so:
.pipe(
map(docArray => {
return docArray.map(doc => {
const data = doc.payload.doc.data() as Exercise;
const idExercise = doc.payload.doc.id;
return {idExercise, ...data};
});
})
)
.pipe(
map(docArray => {
return docArray.map(doc => {
return {
id: doc.payload.doc.id,
...doc.payload.doc.data() as Exercise
};
});
})
)

Resources