【问题标题】:JavaScript file looks OK to me but getting a syntax errorJavaScript 文件对我来说看起来不错,但出现语法错误
【发布时间】:2018-12-06 03:06:23
【问题描述】:

当我运行我的咖啡脚本测试应用程序时,我收到了这个错误”

2018-12-06 02:19:24,681 <NodeTest> [ERROR] [MainThread] node_test.run - NodeJS test for Node v7.9.0 did not pass. Exit status: 1
Std Out: 
Std Error: /opt/node_js/conf.js:25
            osVersion: 'MyOS 1.10.1.21
                       ^^^^^^^^^^^^^^^^^

SyntaxError: 无效或意外的令牌

这是conf.js的内容:

const require('https');
module.exports = {
  // Endpoint
  endpoint: 'https://123.456.789.876',

  // creds
  access: 'accessblablabla',
  secret: 'secret blablabla',

  // Other options
  s3BucketEndpoint: false,
  s3ForcePathStyle: true,
  httpOptions: {
    agent: new https.Agent({ca: '-----BEGIN CERTIFICATE-----'})
  },

  // OS version
  myOsVersion: 'MyOS 1.10.1.21'
}

我不明白为什么myOsVersion: '%s 与文件中的其他任何内容相比有什么不同。谁能发现我做错了什么?

【问题讨论】:

  • %s 是什么意思?我将其粘贴到节点 repl 中,它没有抱怨。赤裸裸的require 是可疑的(可能什么也没做)

标签: javascript syntax-error unexpected-token


【解决方案1】:

我根本不使用 MacOS,但在我看来,我认为你应该声明:

const https = require('https');

在您的代码顶部,因为我看到您使用了 this 的实例(new 关键字)。希望这可以帮助你一点!

【讨论】:

  • 旁注:与 MacOS 完全无关
【解决方案2】:

原来问题是字符串中的空格。

与@phix 的评论一样,如果我手动创建文件,则没有问题。我有一个生成它的 Python 应用程序。也许它包括一些隐藏的角色或其他东西。

无论如何,我只需要字符串中的版本号,因此将我的 Python 代码编辑为如下所示:

version = std_out.split()[1]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-12-27
    • 1970-01-01
    • 2015-10-06
    • 1970-01-01
    相关资源
    最近更新 更多