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

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.

Related

Getting started with Mongoose

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.

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

Resolving template string interpolation at run-time, not at bundle creation time

I have a JavaScript application that is bundled into a client-side application and run in the browser.
An old version of the application used to have a variable assignment like this:
const API_ROOT_URL = `http://${window.location.hostname}:8000/`;
This would presumably get interpolated in the browser.
However, this code now throws a webpack error on webpack 4.42.0:
ReferenceError: window is not defined
at Object.<anonymous> (/usr/src/app/src/client_config.js:4:32)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at Object.<anonymous> (/usr/src/app/webpack.config.js:1:99)
at Module._compile (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:192:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (/usr/src/app/node_modules/webpack-cli/node_modules/v8-compile-cache/v8-compile-cache.js:161:20)
at WEBPACK_OPTIONS (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:114:13)
at requireConfig (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:116:6)
at /usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:123:17
at Array.forEach (<anonymous>)
at module.exports (/usr/src/app/node_modules/webpack-cli/bin/utils/convert-argv.js:121:15)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:71:45
at Object.parse (/usr/src/app/node_modules/yargs/yargs.js:567:18)
at /usr/src/app/node_modules/webpack-cli/bin/cli.js:49:8
at Object.<anonymous> (/usr/src/app/node_modules/webpack-cli/bin/cli.js:366:3)
at Module._compile (internal/modules/cjs/loader.js:1138:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
at Module.load (internal/modules/cjs/loader.js:986:32)
at Function.Module._load (internal/modules/cjs/loader.js:879:14)
at Module.require (internal/modules/cjs/loader.js:1026:19)
at require (internal/modules/cjs/helpers.js:72:18)
at Object.<anonymous> (/usr/src/app/node_modules/webpack/bin/webpack.js:156:2)
It seems that the interpolation is happening at the time the bundle is created, when window doesn't exist.
Can I get the intended behavior?

Module version mismatch

bcrypt seems like has mismatch with node.
my node version is 4.2.1
Error: Module version mismatch. Expected 46, got 14.
at Error (native)
at Object.Module._extensions..node (module.js:460:18)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at bindings (/opt/app/app/node_modules/bcrypt/node_modules/bindings/bindings.js:76:44)
at Object.<anonymous> (/opt/app/app/node_modules/bcrypt/bcrypt.js:3:35)
at Module._compile (module.js:435:26)
at Object.Module._extensions..js (module.js:442:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:311:12)
at Module.require (module.js:366:17)
at require (module.js:385:17)
at Object.<anonymous> (/opt/app/app/controllers/account.js:10:14)
at Module._compile (module.js:435:26)
You (typically) have to recompile addons when switching between "major" versions of node (e.g. v0.10, v0.12, 4.0, 5.0, etc). So an npm rebuild should do just this for you.

Categories

Resources