node.js - 如何修复“语法错误:应为“#”、“\n”、“\r”或[\t],但找到“[”。” yargs 模块检索哪个?
问题描述
我目前正在使用 bitbucket 管道进行持续部署。我已将“npm test”命令放入管道中,因为我使用 mocha 对我的节点项目进行单元测试。
当我在本地 shell 上运行“npm test”来测试我的路由时,它们每个都可以工作。但是当 bitbucket 的临时服务器运行命令时,我检索到这个错误:
stork@1.0.0 test /opt/atlassian/pipelines/agent/build
> mocha tests/**/*.js
/opt/atlassian/pipelines/agent/build/node_modules/mocha/node_modules/yargs/yargs.js:1163
else throw err
^
SyntaxError: Expected "#", "\n", "\r" or [ \t] but "[" found.
npm ERR! Test failed. See above for more details.
我最近在我的存储库中实现了一个 config.toml 文件,以便在我的代码中放入一些变量(如域、路径等)。从那一刻起,在管道中运行的单元测试不再起作用。
这是 toml 解析的问题吗?
这是我的 toml 文件:
title = "configuration"
[charlie]
domain = "localhost"
path = "/"
port = 3000
任何提示都应该非常感激。
解决方案
经过一番研究,我找到了问题的根源。
在 gitignore 文件中提到了我的 toml 文件,不要将它放在我的远程存储库中。
这就是为什么我必须复制/过去整个 toml 内容以将其放入单个 bitbucket 环境变量中的原因。有了这个技术,我肯定在我的服务器上有一个 config.toml 的 prod 版本,在我的机器上有一个 config.toml 的 dev 版本。
问题是我的 BitBucket 变量已被格式化为一行。实际上,toml 格式对换行敏感。这就是为什么我使用 json 而不是 toml 并且问题已得到解决的原因。
推荐阅读
- c++ - 在 DirectX11 中,如何将纹理环绕方向从 U 更改为 V,反之亦然?
- python - 如何使用python从网站下载视频
- bash - 在 bash 上逐行读取文件;每一行都包含另一个 unqiue 文件的路径
- javascript - 将 JS 项目转换为 TypeScript 项目
- python - OpenCV返回关键点的python多进程问题
- sql - 如何执行返回“01-JAN-1900”的查询
- json - 在任何级别使用 jq 搜索字符串
- windows-10 - 传入通知
- jquery - 尝试使用选择类型创建 20 行,并附加到它们。(jQuery、Handlebars 和 HTML)
- python - 通过旋转多列来重塑 DataFrame