Invalid shorthand property initializer error connecting to Mongo DB Atlas - express

I want to connect my project to Mongo DB Atlas. It shows the following error while connecting the Database:
me :~/Desktop/prod$ npm run server
> #0.1.0 server /home/me/Desktop/
> nodemon server.js
[nodemon] 2.0.4 [nodemon] to restart at any time, enter `rs` [nodemon] watching path(s): *.* [nodemon] watching extensions:
js,mjs,json [nodemon] starting `node server.js` Url/keys.js:2
mongoURI = "mongodb+srv://<username>:<password>#cluster0-ttxhq.mongodb.net/test"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SyntaxError: Invalid shorthand property initializer
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:616:28)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at Object.<anonymous> (/home/saurabh/Desktop/prod/server.js:10:12)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10) [nodemon] app crashed - waiting for file changes before starting...
My code is :
const express = require("express")
const mongoose = require("mongoose")
const bodyParser = require("body-parser")
const app = express()
app.use(bodyParser.json())
const db = require("./config/keys").mongoURI
mongoose
.connect(db, {
useNewUrlParser: true,
useCreateIndex : true,
useUnifiedTopology : true
})
.then(()=>console.log("Database Connected"))
.catch(err => console.log(err))
const port = process.env.PORT || 5000
app.listen(port, ()=> console.log(`Server Starter on port ${port}`))
keys.js file is:*
modules.exports = {
mongoURI = "MONGODBURI"
}

Try:
modules.exports = {
mongoURI: "MONGODBURI"
}
This is a JSON so we cannot use '=' here.

have you tried IP whitelisting yourAtlas MongoDB cluster?
https://docs.atlas.mongodb.com/security-whitelist/
Medium tutorial

Related

react native android error after upgrade to 0.67.2 - SyntaxError: Unexpected token =

I have just upgraded from RN 0.63.3 to 0.67.2...and Im now receiving an error when I try to clean project in Android studio
....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350 processRequest = (req, res, next) => { ^SyntaxError: Unexpected token = at Module._compile (internal/modules/cjs/loader.js:721:23) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10) at Module.load (internal/modules/cjs/loader.js:653:32) at tryModuleLoad (internal/modules/cjs/loader.js:593:12) at Function.Module._load (internal/modules/cjs/loader.js:585:3) at Module.require (internal/modules/cjs/loader.js:690:17) at require (internal/modules/cjs/helpers.js:25:18) at Object.<anonymous> (....node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\shared\output\bundle.js:12:16) at Module._compile (internal/modules/cjs/loader.js:776:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
If you look at the file path its referring to (node_modules\#react-native-community\cli-plugin-metro\node_modules\metro\src\Server.js:350)...this is the line of code where its unhappy
processRequest = (req, res, next) => {
this._processRequest(req, res, next).catch(next);
};
Upgrading node to latest version fixed the issue

When in localhost AdminBro bundle function is taking path, but when deployed to the Vercel production getting error, why?

In the local server, it is working correctly. Only when deployed to Vercel getting this error.
This is the following code - (The error is occurring in the AdminBro.bundle as it is not taking the argument.)
imagePath: {
isVisible: { list: false, filter: false, show: true, edit: true },
components: {
show: AdminBro.bundle(
"components/admin-imgPath-component.jsx"
),
},
},
The error I am getting.
2021-08-26T18:14:08.075Z undefined ERROR ConfigurationError:
Given file "components/admin-imgPath-component.jsx", doesn't exist.
More information can be found at: https://softwarebrothers.github.io/admin-bro-dev/AdminBro.html
at Function.bundle (/var/task/node_modules/admin-bro/lib/admin-bro.js:375:13)
at Object.<anonymous> (/var/task/routes/admin.js:47:30)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at Module.require (internal/modules/cjs/loader.js:961:19)
at require (internal/modules/cjs/helpers.js:92:18)
at Object.<anonymous> (/var/task/app.js:25:21)
at Module._compile (internal/modules/cjs/loader.js:1072:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1101:10)
at Module.load (internal/modules/cjs/loader.js:937:32)
at Function.Module._load (internal/modules/cjs/loader.js:778:12)
at ModuleWrap.<anonymous> (internal/modules/esm/translators.js:199:29)
at ModuleJob.run (internal/modules/esm/module_job.js:170:25)
at async Loader.import (internal/modules/esm/loader.js:178:24)
RequestId: ce1bf09a-857f-4c40-8a3b-e8a1762590bb Error: Runtime exited with error: exit status 1
Runtime.ExitError
You have to call
show: AdminBro.bundle(
"components/admin-imgPath-component"
),
WITHOUT extension at the end.
Make sure that adminjs automatically generates an folder with file .adminjs/.entry.js where the Component gets linked to the AdminJS instance.

While unit React-native test files with Mocha, it gives error unexpected tocken

In a React-native project, I want to setup unit testing, For this I am using Mocha and Chai. When I run command npm test it executes mocha __tests__/*.js internally. In test file my code is following:
import { expect } from 'chai';
import Adapter from 'enzyme-adapter-react-16';
import { RefundedEmd } from './RefundedEmd';
import React from 'react';
import renderer from 'react-test-renderer';
describe('App', () => {
it('renders correctly', () => {
renderer.create(<App />);
});
});
I get following error in console:
C:\Technical work\Lorex\slf-mobile-impl\__tests__\App-test.js:1
import { expect } from 'chai';
^
SyntaxError: Unexpected token {
at Module._compile (internal/modules/cjs/loader.js:723:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Module.require (internal/modules/cjs/loader.js:692:17)
at require (internal/modules/cjs/helpers.js:25:18)
at C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:311:36
at Array.forEach (<anonymous>)
at Mocha.loadFiles (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:308:14)
at Mocha.run (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\mocha.js:849:10)
at Object.exports.singleRun (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:108:16)
at exports.runMocha (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run-helpers.js:143:13)
at Object.exports.handler.argv [as handler] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\run.js:305:3)
at Object.runCommand (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\lib\command.js:242:26)
at Object.parseArgs [as _parseArgs] (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:1087:28)
at Object.parse (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\node_modules\yargs\yargs.js:566:25)
at Object.exports.main (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\lib\cli\cli.js:68:6)
at Object.<anonymous> (C:\Technical work\Lorex\slf-mobile-impl\node_modules\mocha\bin\mocha:133:29)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:622:3)
npm ERR! Test failed. See above for more details.

How to use ssr supported packages in vue with vue-server-renderer?

I tried to use vue2-google-maps and it worked well.
Suddenly my computer had stopped working and then I restarted my computer.
Then, strangely, 500-error comes out.
I reverted all codes associated with vue2-google-maps then my project works well.
Even though when I import vue2-google-maps then It occurs 500-error. :(
App.js
import * as VueGoogleMaps from 'vue2-google-maps';
It was working well but now cause of the unknown reason it has been broken...
Here is my console shows error.
webpack built 5410edae88d11b814c0b in 2690ms
error during render : /search
/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/components/infoWindow.vue:3
<template>
^
SyntaxError: Unexpected token <
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/main.js:42:19)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at r (/media/bossminion/Work/WeMeet/frontend/node_modules/vue-server-renderer/build.dev.js:9295:16)
at Object.<anonymous> (webpack:/external "vue2-google-maps":1:0)
at __webpack_require__ (webpack:/webpack/bootstrap a442baf8af813fadc2a4:25:0)
error during render : /favicon.ico
/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/components/infoWindow.vue:3
<template>
^
SyntaxError: Unexpected token <
at Module._compile (internal/modules/cjs/loader.js:720:23)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at Object.<anonymous> (/media/bossminion/Work/WeMeet/frontend/node_modules/vue2-google-maps/dist/main.js:42:19)
at Module._compile (internal/modules/cjs/loader.js:776:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
at Module.load (internal/modules/cjs/loader.js:643:32)
at Function.Module._load (internal/modules/cjs/loader.js:556:12)
at Module.require (internal/modules/cjs/loader.js:683:19)
at require (internal/modules/cjs/helpers.js:16:16)
at r (/media/bossminion/Work/WeMeet/frontend/node_modules/vue-server-renderer/build.dev.js:9295:16)
at Object.<anonymous> (webpack:/external "vue2-google-maps":1:0)
at __webpack_require__ (webpack:/webpack/bootstrap a442baf8af813fadc2a4:25:0)
Is it possible that project that worked well could cause 500-error for no reason?
Environment: Ubuntu 18.04, npm v6.9.0, node v12.6.0
I have found how to handle ssr.
App.js
if (process.browser) {
const VueGoogleMaps = require('vue2-google-maps');
Vue.use(VueGoogleMaps, {
load: {
key: 'myKey',
libraries: 'places',
},
});
}
Instead of using import, I used require when it is client rendering.
I will be happy if it helped you. :D

How can I retry failed end to end tests in Detox using Mocha?

I have a flaky end-to-end test that uses Detox and Mocha.
The Mocha test runner allows for multiple retries. I tried using the recommended Mocha syntax:
// auth.spec.js
describe('App authentication', () => {
this.retries(2);
it('should have a login screen', async () => {
await expect(element(by.id('LoginScreenView'))).toBeVisible();
});
});
However, it appears this is an empty object ({}) and does not have a retries function when running Detox with Mocha as the test runner.
It generates the following error:
node_modules/.bin/mocha __e2e__ --opts __e2e__/config/mocha.opts --
configuration ios.sim.debug --grep :android: --invert --artifacts-location "__e2e__/artifacts/ios.sim.debug.2018-10-17 22-51-12Z"
/<path>/__e2e__/auth.spec.js:10
this.retries(2);
^
TypeError: this.retries is not a function
at Suite.describe (/<path>/__e2e__/auth.spec.js:4:8)
at Object.create (/<path>/node_modules/mocha/lib/interfaces/common.js:112:19)
at context.describe.context.context (/<path>/node_modules/mocha/lib/interfaces/bdd.js:40:27)
at Object.<anonymous> (/<path>/__e2e__/auth.spec.js:3:1)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Module.require (module.js:596:17)
at require (internal/module.js:11:18)
at /<path>/node_modules/mocha/lib/mocha.js:250:27
at Array.forEach (<anonymous>)
at Mocha.loadFiles (/<path>/node_modules/mocha/lib/mocha.js:247:14)
at Mocha.run (/<path>/node_modules/mocha/lib/mocha.js:576:10)
at Object.<anonymous> (/<path>/node_modules/mocha/bin/_mocha:637:18)
at Module._compile (module.js:652:30)
at Object.Module._extensions..js (module.js:663:10)
at Module.load (module.js:565:32)
at tryModuleLoad (module.js:505:12)
at Function.Module._load (module.js:497:3)
at Function.Module.runMain (module.js:693:10)
at startup (bootstrap_node.js:188:16)
at bootstrap_node.js:609:3
child_process.js:644
throw err;
^
Is there a way to automatically retry failed tests in Detox?
this in mocha can't work with arrow function, so must change it into ordinary one
// auth.spec.js
describe('App authentication', function () { // change it
this.retries(2);
It is not recommended best practice to use in Mocha
Ref:
https://mochajs.org/#arrow-functions
Hope it helps