简体   繁体   English

使用节点JavaScript的意外令牌ILLEGAL

[英]Unexpected token ILLEGAL using node javascript

I am trying to execute a command using node JavaScript, but I am getting "Uncaught SyntaxError: Unexpected token ILLEGAL" in my javascript.Its on line 1. 我正在尝试使用节点JavaScript执行命令,但是我的javascript中出现了“未捕获的SyntaxError:意外令牌ILLEGAL”。它位于第1行。

 var express = require('express'); var mongodb = require('mongodb'); var app = express(); var MongoClient = require('mongodb').MongoClient; var db; var port = process.env.PORT || 8080; MongoClient.connect(mongo_host, function(err, database) { if(err) throw err; db = database; app.listen(port, function () { console.log('listening port' + port); }); }); app.get('/', function (req, res) { res.json({ message: 'Bienvenue Azure!' }); }); app.get('/plante', function (req, res) { db.collection("plante").find().toArray(function(err, users) { res.send(users); }); }); 

NB: mongo_host is the Git repository url to connect with azure 注意:mongo_host是用于与azure连接的Git存储库URL

Then it is showing the following error: 然后显示以下错误:

 SyntaxError: Unexpected token ILLEGAL at exports.runInThisContext (vm.js:53:16) at Module._compile (module.js:404:25) at Object.Module._extensions..js (module.js:432:10) at Module.load (module.js:356:32) at Function.Module._load (module.js:313:12) at Function.Module.runMain (module.js:457:10) at startup (node.js:138:18) at node.js:974:3 

Your semicolons aren't standard semicolons. 您的分号不是标准分号。 They are ( Greek Question Mark ). 它们是希腊问号 )。 Try switching them back to standard semicolons and then running the code. 尝试将它们切换回标准分号,然后运行代码。

Someone has been reading twitter . 有人一直在读推特

As @dvlsg said, it's a syntax error which caused by some illegal symbols like . 正如@dvlsg所说,这是一种语法错误,是由等非法符号引起的。

There was a similiar SO thread which be helpful for you, please see No visible cause for "Unexpected token ILLEGAL" . 有一个类似的SO线程对您有帮助,请参阅“ 无意外的令牌ILLEGAL”的可见原因

I solved this error by updating my node version in the Azure web app service to the latest (10.6.0 in my case). 我通过将Azure Web应用程序服务中的节点版本更新为最新版本(本例中为10.6.0)解决了该错误。 It had been balking at the lines containing ES6. 它一直对包含ES6的代码不满意。 One way to change that is with an environment variable. 一种更改方法是使用环境变量。 You can change it in 'Application settings' in your app's portal. 您可以在应用程序门户的“应用程序设置”中进行更改。 Change WEBSITE_NODE_DEFAULT_VERSION 变更WEBSITE_NODE_DEFAULT_VERSION

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM