Missing one Necessary Argument: dataSource - datasource

this is my package json
"scripts": {
"build": "tsc",
"dev:server": "ts-node-dev --inspect --transpile-only --ignore-watch node_modules src/server.ts",
"typeorm": "ts-node-dev ./node_modules/typeorm/cli.js"
},
this is my ormconfig.json
{
"type": "postgres",
"host": "localhost",
"port": 5432,
"username": "test",
"password": "test",
"database": "gostack_gobarber",
"migrations": [
"./src/database/migrations/*.ts"
],
"cli": {
"migrationsDir": "./src/database/migrations"
}
}
yarn typeorm migration:create - CreateAppointments i created this files, put my new table here
yarn typeorm migration:run Now i have to execute this but, my terminal comes with a error saying that i need dataSource file. Please someone help me, i tryed some things that i found here but no sucess. if you can explain in details whats i should do

[SOLVED]
ormconfig is no longer supported after version 0.3.0
Solution
In a nutshell: TypeORM is expecting to find a DataSource() instance.
How to do this?
Short answer
// datasource.ts
import { DataSource } from 'typeorm';
const ormConfig = { /* Add your config here */ };
export default new DataSource(OrmConfig);
Then use the -d in the TypeORM command to specify the path to the datasource.
Example: typeorm migration:generate path/to/Migration -d path/to/datasource
Long answer
// orm.config.ts
import { DataSource } from 'typeorm';
// Note: use your corresponding Database config
import { PostgresConnectionOptions } from 'typeorm/driver/postgres/PostgresConnectionOptions';
// General DB connection config
const ormConfig: PostgresConnectionOptions = {
type: 'postgres',
host: process.env.DB_HOST,
port: parseInt(<string>process.env.DB_PORT),
username: process.env.DB_USERNAME,
password: process.env.DB_PASSWORD,
database: process.env.DB_NAME,
logging: true,
entities: ['path/to/entities'],
migrations: ['path/to/migrations'],
synchronize: false,
ssl: true,
};
export default new DataSource(ormConfig);
package.json
"scripts": {
"migration:create": "typeorm migration:create ./path/to/migration",
"migration:generate": "typeorm migration:generate -d ./path/to/datasource ./path/to/migration",
"migration:run": "typeorm migration:run -d ./path/to/datasource"
},

Related

how to configure cypress-sql-server to be used in different environments prod and dev

I'm using cypress-sql-server plugin to be configured based on different environments for production.json and development.json
{
"env": {
"userName":"sa",
"password": "",
"server": "localhost",
"port": "1433",
"options": {
"database": "TestDatabase",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
}
the index.js file in the plugins
const path = require("path");
const fs = require("fs-extra");
const sqlServer = require('cypress-sql-server');
function getConfigurationByFile(file) {
const pathToConfigFile = path.resolve("cypress/config", ${file}.json)
console.error('the server path',pathToConfigFile)
return fs.readJson(pathToConfigFile);
}
module.exports = async (on, config) => {
tasks = sqlServer.loadDBPlugin(config);
on('task', tasks);
const file = config.env.fileConfig
return getConfigurationByFile(file)
}
when I run the test case I get the failure message as below
cy.task('sqlServer:execute') failed with the following error:
Invalid server: undefined"
I replace localhost with machine name, but same error.I think sqlServer.loadDBPlugin(config) is not getting right data.
Any idea guys?
Please help.
Thanks.
I had the same problem and replaced the cypress-sql-server with the tedious one directly. Using these:
https://github.com/cypress-io/cypress/issues/6621
Note: install the fixed version:
"coffeescript": "^2.5.1",
"tedious": "^ 8.3.0"
Did you specify that in your cypress.json or other configuration file like so?
Your cypress.json (or environment specific files in the config
directory) should specify the DB redentials in the following format
"db": {
"userName": "",
"password": "",
"server": "",
"options": {
"database": "",
"encrypt": true,
"rowCollectionOnRequestCompletion" : true
}
}
Source: https://www.npmjs.com/package/cypress-sql-server

inject is not defined - CodeceptJs and CucumberJs

It's my first time using CodeceptJs and I'm struggling to run my feature file as the IDE asks me to implement steps for my scenario but this is already done, so I feel it may be searching for them somewhere other than the specified under the codecept.conf.js file?
When I run npx codeceptjs gherkin:steps or snippets on the terminal I get this message saying Could not include object Step Definition from ./step_definitions/steps.js from module '/Users/myUser/IdeaProjects/codeceptjs_webdriver/step_definitions/steps.js' The "from" argument must be of type string. Received undefined .
I then move the step_definitions folder to inside features as read that this would be the default location for these and now get an inject is not defined error, which may be the actual cause for the issue I'm getting, but not sure what to do to fix it.
I've tried on IntelliJ Ultimate, Webstorm and VSCode but get the same on all of them.
basic.feature
Feature: Business rules
In order to achieve my goals
As a persona
I want to be able to interact with a system
Scenario: do something
Given I have a defined step
steps.js
const {Given} = require('cucumber');
const {I} = inject();
Given(/^I have a defined step$/, function () {
I.amOnPage('/');
});
codecept.conf.js
exports.config = {
output: './output',
helpers: {
WebDriver: {
url: 'https:www.google.com',
browser: 'chrome'
}
},
include: {
I: './steps_file.js'
},
mocha: {},
bootstrap: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js']
},
plugins: {
screenshotOnFail: {
enabled: true
},
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
tryTo: {
enabled: true
}
},
tests: './*_test.js',
name: 'codeceptjs_webdriver'
}
package.json
{
"name": "codeceptjs_webdriver",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"codeceptjs": "^3.0.0",
"cucumber": "^5.0.1"
},
"dependencies": {
"#codeceptjs/configure": "^0.6.0"
},
"description": ""
}
IntelliJ Ultimate 2020.2
And here my Github repo
Thank you very much.
It's working now and I've come back to update it here if useful to someone else.
Was able to keep the steps under step_definitions/steps folder (not the one inside the features folder). To fix the non implemented issue had to install the wdio dependency. In order for this to take effect properly through running npm install both node_modules and package-lock.json had to be deleted to be freshly regenerated.
updated package.json
{
"name": "codeceptjs_webdriver",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "npx codeceptjs run"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {},
"dependencies": {
"#wdio/selenium-standalone-service": "^6.6.2",
"codeceptjs": "^2.6.8",
"codeceptjs-assert": "0.0.4",
"webdriverio": "6.3.6"
},
"description": ""
}
updated codecept.conf.js
exports.config = {
output: './output',
helpers: {
WebDriver: {
url: 'https://www.google.com',
browser: 'chrome'
}
},
include: {
I: './steps_file.js'
},
mocha: {},
bootstrap: null,
teardown: null,
hooks: [],
gherkin: {
features: './features/*.feature',
steps: ['./step_definitions/steps.js']
},
plugins: {
wdio: {
enabled: true,
services: ['selenium-standalone']
// additional config for service can be passed here
},
screenshotOnFail: {
enabled: true
},
pauseOnFail: {},
retryFailedStep: {
enabled: true
},
},
tests: './*_test.js',
name: 'codeceptjs_webdriver'
}

Critical dependency: the request of a dependency is an expression, vue.js

My testing-app is compiling fine, except that I get this warning:
" Critical dependency: the request of a dependency is an expression"
(base) marco#pc01:~/webMatters/vueMatters/PeerJS-VueJS-Test$ npm run serve
> testproject#0.1.0 serve /home/marco/webMatters/vueMatters/PeerJS-VueJS-Test
> vue-cli-service serve
INFO Starting development server...
98% after emitting CopyPlugin
WARNING Compiled with 1 warnings
7:22:25 PM
warning in ./node_modules/peerjs/dist/peerjs.min.js
Critical dependency: the request of a dependency is an expression
App running at:
- Local: http://localhost:8080
- Network: http://ggc.world/
Note that the development build is not optimized.
To create a production build, run npm run build.
I read around that it might depend of webpack, but didn't find how to put it right.
This is webpack.config.js :
{
"mode": "development",
"output": {
"path": __dirname+'/static',
"filename": "[name].[chunkhash:8].js"
},
"module": {
"rules": [
{
"test": /\.vue$/,
"exclude": /node_modules/,
"use": "vue-loader"
},
{
"test": /\.pem$/,
"use": "file-loader"
}
]
},
node: {
__dirname: false,
__filename: false
},
resolve: {
extension: ['*', '.pem'],
},
devServer: {
watchOptions: {
aggregateTimeout: 300,
poll: 1000
},
https: true,
compress: true,
public: 'ggc.world:8080'
}
}
Any ideas about how to solve it?
The following code works for me. Edit vue.config.js and add webpack config:
configureWebpack: {
module: {
exprContextCritical: false
}
}
const webpack = require('webpack');
module.exports = {
// ... your webpack configuration ...
plugins: [
new webpack.ContextReplacementPlugin(
/\/package-name\//,
(data) => {
delete data.dependencies[0].critical;
return data;
},
),
]
}
try this one
For people coming here using CRA and having trouble with PeerJS, install react-app-rewired and use the following override config and it should work.
/* config-overrides.js */
const webpack = require('./node_modules/webpack')
module.exports = function override (config, env) {
if (!config.plugins) {
config.plugins = []
}
config.plugins.push(
new webpack.ContextReplacementPlugin(
/\/peerjs\//,
(data) => {
delete data.dependencies[0].critical
return data
}
)
)
return config
}
It seems it is an error between the library bundler (parcel) and CRA bundler (webpack), and I couldn't find any official fix on the way.

cannot read property to String of undefined [sequelize db:migrate node.js postgres]

I run
$ sequelize db:migrate,
but I get this result, with an ERROR
Loaded Configuration file "db\config\config.json".
Using environment "development".
==20190927081141-add-email-to-contacts: migrating =======
ERROR: Cannot read property 'toString' of undefined
This is my current config.json file, but I don't have any toString property in it.
//config.json
{
"development": {
"port":5432,
"username": "postgres",
"password": null,
"database": "address-bloc-dev",
"host": "127.0.0.1",
"dialect": "postgres",
"logging":false
},
"test": {
"username": "postgres",
"password": null,
"database": "address-bloc-test",
"host": "127.0.0.1",
"dialect": "postgres",
"logging": false
}
}
Here is also the add email to contacts.js file
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Contacts', 'email',
{
email: {
type: Sequelize.STRING,
}
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Contacts', 'email');
}
};
What am I doing wrong? I'm struggling in figuring it out.
Thank you
Federico
Had a similar issue with
changeColumn(), ensure that that you completely define the new data type of the column that you intend to change.
Sequelize Docs
This method changes the meta data of an attribute. It is possible to change the default value, allowance of null or the data type. Please make sure, that you are completely describing the new data type.
This error is not coming from the config.json file, but rather the 20190927081141-add-email-to-contacts. The error is from there.
EDIT:
What you are doing wrong is how you are setting the type of the email field.
You should do:
'use strict';
module.exports = {
up: (queryInterface, Sequelize) => {
return queryInterface.addColumn('Contacts', 'email',
{
type: Sequelize.STRING,
});
},
down: (queryInterface, Sequelize) => {
return queryInterface.removeColumn('Contacts', 'email');
}
};
I have this error and the solution was to modify just a word.
the place of the error
id:{
ype: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true,
allowNull: false,
}
the solution was
id:{
type: DataTypes.UUID,
defaultValue: DataTypes.UUIDV1,
primaryKey: true,
allowNull: false,
}
just added the missing letter
follow steps below:
install sequelize-cli: npm install -g sequelize-cli
install sequelize: npm install --save sequelize
install mysql2: npm install --save mysql2
initialize sequelize: sequelize init
delete the migration and seeder directory automatically generated
create a model (e.g user model):
module.exports = (sequelize, DataTypes) => {
const User = sequelize.define('users', {
name: {
type: Datatype.STRING,
allowNull: false,
},
userRole: {
type: Datatype.INTEGER,
allowNull: false,
},
});
return User;
}
Add db.sequelize.sync({ force: true, logging: console.log }); to your server.js after db has been defined.
run your server

Aurelia using featherjs dependency failing to properly import

How do you import featherjs using the style common in Aurelia projects. This is what I have:
in the build file aurelia.json
"dependencies": [
{
"name": "socket.io-client",
"path": "../node_modules/socket.io-client/dist/socket.io.min"
},
{
"name": "feathers",
"path": "../node_modules/feathers",
"main": "client",
"env": "dev"
},
"aurelia-binding",
In the app.js
import io from 'socket.io-client';
import feathers from 'feathers';
//import socketio from 'feathers-socketio';
export class App {
constructor() {
this.message = 'Hello World!';
console.log("startup");
const socket = io('http://localhost:3030');
const app = feathers();
// .configure(socketio(socket));
}
}
The error looks like this:
Starting 'readProjectConfiguration'...
Finished 'readProjectConfiguration'
Starting 'processMarkup'...
Starting 'processCSS'...
Starting 'configureEnvironment'...
Finished 'processCSS'
Finished 'processMarkup'
Finished 'configureEnvironment'
Starting 'buildJavaScript'...
Finished 'buildJavaScript'
Starting 'writeBundles'...
Tracing app...
{ uid: 8,
name: 'writeBundles',
branch: false,
error:
{ [Error: ENOENT: no such file or directory, open '/Users/steve/project/src/uberproto.js']
errno: -2,
code: 'ENOENT',
syscall: 'open',
path: '/Users/steve/project/src/uberproto.js',
moduleTree: [ 'feathers/lib/feathers' ],
fileName: '/Users/steve/project/node_modules/feathers/lib/feathers.js' },
duration: [ 0, 161365129 ],
time: 1484844203606 }
Once it gets into processing the dependency it seems to be having path confusion looking for dependencies in featherjs. I'm pretty new with this stuff, so it is likely something simple, but I haven't figured out the correct way to include this dependency.
I believe what you want to install is feathers-client not feathers.
npm i -S feathers-client
aurelia.json:
{
"name": "socket.io-client",
"path": "../node_modules/socket.io-client/dist/socket.io.min"
},
{
"name": "feathers-client",
"path": "../node_modules/feathers-client/dist",
"main": "feathers"
}
app.js:
import io from 'socket.io-client';
import feathers from 'feathers-client';
export class App {
constructor() {
const socket = io('http://localhost:3030');
const app = feathers().configure(feathers.socketio(socket));
}
}
You're missing the main property. The configuration should be like this:
{
"name": "socket.io-client",
"path": "../node_modules/socket.io-client/dist",
"main": "socket.io.min"
}