SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._pile (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:\server\index.js:2:13)
I am getting this error when i run gulp dev This happens only on windows , it is running fine in linux and the server is getting started on linux
Below is the Snippet
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
mongoose.connect('mongodb://localhost/testdb');
const dbConnection = mongoose.connection;
dbConnection.on(
'error',
console.error.bind(console, 'Connection Error:')
);
dbConnection.once(
'open',
() => {
console.log('DB connection successful');
}
);
I get this error at 12th line ,
However when i write it this way I won't get any error and server starts
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
mongoose.connect('mongodb://localhost/emerce');
const dbConnection = mongoose.connection;
dbConnection.on('error', console.error.bind(console, 'Connection Error:'));
dbConnection.once('open',()=>{console.log('DB connection successful');});
What is the reason behind this ?
SyntaxError: Unexpected token )
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._pile (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:\server\index.js:2:13)
I am getting this error when i run gulp dev This happens only on windows , it is running fine in linux and the server is getting started on linux
Below is the Snippet
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
mongoose.connect('mongodb://localhost/testdb');
const dbConnection = mongoose.connection;
dbConnection.on(
'error',
console.error.bind(console, 'Connection Error:')
);
dbConnection.once(
'open',
() => {
console.log('DB connection successful');
}
);
I get this error at 12th line ,
However when i write it this way I won't get any error and server starts
const express = require('express');
const bodyParser = require('body-parser');
const mongoose = require('mongoose');
const routes = require('./routes');
mongoose.connect('mongodb://localhost/emerce');
const dbConnection = mongoose.connection;
dbConnection.on('error', console.error.bind(console, 'Connection Error:'));
dbConnection.once('open',()=>{console.log('DB connection successful');});
What is the reason behind this ?
Share Improve this question asked Nov 27, 2017 at 13:31 manojthetechguymanojthetechguy 611 gold badge2 silver badges8 bronze badges 7-
What version of node are you running on Windows? The
() => { ... }
arrow function notation is new(ish), so if you're running an older node version on windows... it won't work. – searlea Commented Nov 27, 2017 at 13:41 - i am using node 6.11.2 and npm 3.10.10 – manojthetechguy Commented Nov 27, 2017 at 14:12
- if it does not work , why is it working in the other way, even that is an arrow function – manojthetechguy Commented Nov 27, 2017 at 14:13
- You said it works on Linux, but not on Windows. Are you running 6.11.2 on both? Is any of the code running through babel, do you have a global/local babel config, is it the same on both platforms? – searlea Commented Nov 27, 2017 at 14:27
- Thanks @searlea , I used nvm and downloaded node 8.9.1 and ran gulp dev on the server folder, It ran fine. I had diff versions running on linux and windows latter one being old – manojthetechguy Commented Nov 29, 2017 at 14:41
2 Answers
Reset to default 1i had the same issue, so i just deleted the bloc of code that was causing the error, and rewrite it, i think it's due to some hidden characters
If somebody falls in this error, major problem is with your node version. Upgrade it to the latest one.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745512867a4630850.html
评论列表(0条)