admin管理员组文章数量:1023758
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.
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.
本文标签:
版权声明:本文标题:javascript - Unexpected token ) at createScript (vm.js:56:10) Node js when running gulp dev only on windows - Stack Overflow 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745512865a2153905.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论