Getting started with Mongoose - javascript

When I put in the code
const mongoose = require("mongoose")
I get back the following error:
/Users/user/shares3/node_modules/mongodb/lib/utils.js:1069
catch {
^
SyntaxError: Unexpected token {
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> (/Users/user/shares3/node_modules/mongodb/lib/operations/add_user.js:6:17)
This code is as simple as could be. I have tried reinstalling the mongoose package.
Do you have any ideas on how I can troubleshoot this?

The issue is caused by using a (very) old version of Node.js that doesn't support try/catch.

Related

Problem to execute gulp server at legacy app

Yo guys!
I get early a job on a legacy app, using gulpjs
After having installed all dependencies, when I try execute the application with "gulp server", get the following error at console:
D:\scripts\node_modules\gulp-sass\index.js:186
).toString();
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (D:\Playkids\playkids-simple-pages\scripts\tasks\development.js:4:12)

optional chaining operator in node modules not working in linux

this is the error i am facing when i try to run the code
const contentType = response?.headers['content-type'];
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 Object. (/home/pranav/mona/monacip-backend/node_modules/#api.video/nodejs-client/lib/index.js:15:38)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
this ?. operator is not working on ubuntu machines

Unexpected token when running grunt build

I'm trying to execute the following command grunt build but when trying it the below error message appear
PS C:\Users\EDMA\Documents\Tutenlabs\Bitbucket\tuten-macarena-backoffice-web> grunt build
C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\micromatch\index.js:44
let isMatch = picomatch(String(patterns[i]), { ...options, onResult }, true);
^^^
SyntaxError: Unexpected token ...
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:549:28)
at Object.Module._extensions..js (module.js:586:10)
at Module.load (module.js:494:32)
at tryModuleLoad (module.js:453:12)
at Function.Module._load (module.js:445:3)
at Module.require (module.js:504:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\findup-sync\index.js:12:10)
I navigate to C:\Users\EDMA\AppData\Roaming\nvm\v6.16.0\node_modules\grunt-cli\node_modules\micromatch\index.js:44 path and looked for index.js file to check whether there's an error or not, but the strange thing is there isn't. Any idea what's going on here?
Aditionally, this is AngularJS.

it gives "SyntaxError: Unexpected token" when importing express-handlebars

when I add this line error appears and if removed error disappears
const expressHandleBars = require('express-handlebars');
This is the error,
C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\lib\express-handlebars.js:230
);
^
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (C:\Users\Hp\sample-project\node-mongodb-api\node_modules\express-handlebars\index.js:9:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
What version of Node.js are you using? Please check this issue.
The error cause by Trailing commas in function call feature. This feature had been implemented in Node v8 so you have to upgrade your Node.js to version 8+ to be able to use express-handlebars.

Making Discord Bot - Syntax Error When Trying to Start

I am relatively new to coding so I followed a simple tutorial on how to create a Discord bot, but when I try to start it by using the command node bot.js in Command Prompt, I get this error:
SyntaxError: Invalid or unexpected token
at new Script (vm.js:73:7)
at createScript (vm.js:245:10)
at Object.runInThisContext (vm.js:297:10)
at Module._compile (internal/modules/cjs/loader.js:657:28)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
at Module.load (internal/modules/cjs/loader.js:599:32)
at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
at Function.Module._load (internal/modules/cjs/loader.js:530:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
at startup (internal/bootstrap/node.js:266:19)
Can someone please help me prevent this error from occurring?

Categories

Resources