【问题标题】:Unexpected token ILLEGAL using node javascript使用节点javascript的意外令牌非法
【发布时间】:2018-10-11 01:15:12
【问题描述】:

我正在尝试使用节点 JavaScript 执行命令,但在我的 javascript.Its on line 1 中出现“Uncaught SyntaxError: Unexpected token ILLEGAL”。

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

【问题讨论】:

    标签: javascript node.js git azure syntax-error


    【解决方案1】:

    您的分号不是标准分号。他们是\u037e (Greek Question Mark)。尝试将它们切换回标准分号,然后运行代码。

    有人一直在阅读twitter

    【讨论】:

      【解决方案2】:

      正如@dvlsg所说,这是由等非法符号引起的语法错误。

      有一个类似的 SO 线程对您有帮助,请参阅No visible cause for "Unexpected token ILLEGAL"

      【讨论】:

        【解决方案3】:

        我通过将 Azure Web 应用服务中的节点版本更新为最新版本(在我的情况下为 10.6.0)解决了这个错误。它一直对包含 ES6 的行犹豫不决。改变它的一种方法是使用环境变量。您可以在应用程序门户的“应用程序设置”中更改它。换WEBSITE_NODE_DEFAULT_VERSION

        【讨论】:

          猜你喜欢
          • 2015-12-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-07-06
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多