使用节点javascript的意外令牌ILLEGAL
Unexpected token ILLEGAL using node javascript
我正试图使用节点JavaScript执行一个命令,但我的JavaScript中出现了"Uncaught SyntaxError:Unexpected token 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);
});
});
注意:mongo_host是连接azure 的Git存储库url
然后显示以下错误:
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
您的分号不是标准分号。它们是'u037e
(希腊语问号)。请尝试将它们切换回标准分号,然后运行代码。
有人一直在看推特。
正如@dvlsg所说,这是由;
等非法符号引起的语法错误。
有一个类似的SO线程对您有帮助,请参阅"没有明显的原因";意外的令牌"非法";。
我通过将Azure web应用程序服务中的节点版本更新到最新版本(在我的情况下为10.6.0)来解决此错误。它一直在犹豫包含ES6的线路。改变这种情况的一种方法是使用环境变量。您可以在应用程序门户的"应用程序设置"中更改它。更改WEBSITE_NODE_DEFAULT_VERSION
相关文章:
- React JS:未捕获(在承诺中)语法错误:在位置 0 的 JSON 中意外<令牌
- jQuery$.getJSON抛出意外令牌
- 为什么我在下面的..of循环中得到意外令牌
- 组件中的ReactJS意外令牌
- AngularJS $http GET 请求到本地 JSON 文件返回语法错误:意外令牌]
- 巴别塔,意外令牌 (15:33) ::.
- Sencha 2.0 和 Codeigniter RESTful API 生成未捕获的语法错误:意外令牌:
- 在事件上使用 jquery 时出现意外令牌
- JSON 中位置 4 处的意外令牌<
- 意外令牌 ) 在我的代码中
- Electron 和 Babel 6 异步/等待抛出意外令牌
- “JSON.parse(str)”返回“意外令牌c”,但str是一个字符串
- jQuery after() uncatch SyntaxError: 意外令牌 ILLEGAL
- 使用节点javascript的意外令牌ILLEGAL
- Javascript/JQuery-Chrome意外令牌
- Ajax 帖子未捕获语法错误:意外令牌非法
- angularjs-SyntaxError:请求从服务器返回时出现意外令牌
- jquery:使用ember的意外令牌C
- React本机项目中的意外令牌
- 解析有效的 JSON 得到“语法错误:意外令牌非法”