在我的 Gulp 文件中加入 2 个字符串会出现无意义的错误?

Joining 2 strings in my Gulp file gives a non-sensical error?

在 OSX 上使用节点 16.2.0。我刚接触 Gulp。

我想更新我的 package.json 文件中的 version,如果在功能分支上,该文件将包含 Git 散列,所以我的 Gulp 中有这个文件

// pkg is defined somewhere else to be my Gulp file
// I have a "semVer" key in my package.json file
const {src, dest} = require('gulp');
const semver = require('semver');
...
const semVer = semver.parse(pkg.semVer);

// Functions getBranch() and getHash() are defined somewhere else,
// and they return the Git branch and hash respectively.
function manageVersion() {
  var newVersion = semver.inc(semVer, 'patch');
  var hash = "";
  if (getBranch().includes('feature')) {
    hash = getHash().toString();
    newVersion = [newVersion, hash].join('-');
  }
  src(['../package*.json'])
    .pipe(gulp_bump({
      version: newVersion
    }))
    .pipe(dest('./'));
}
exports.manageVersion = manageVersion

然后我这样做,得到了无意义的错误

$ gulp manageVersion -f gulpfiles/version.js

[16:20:20] Working directory changed to /path/gulpfiles
[16:20:20] Using gulpfile /path/gulpfiles/version.js
[16:20:20] Starting 'manageVersion'...
[16:20:20] Finished 'manageVersion' after 99 ms
/path/node_modules/semver/semver.js:564
        if (v1[key] !== v2[key]) {
                          ^

TypeError: Cannot read property 'major' of null
    at Function.diff (/path/node_modules/semver/semver.js:564:27)
    at /path/node_modules/bump-regex/index.js:66:26
    at String.replace (<anonymous>)
    at module.exports (/path/node_modules/bump-regex/index.js:54:23)
    at DestroyableTransform._transform (/path/node_modules/gulp-bump/index.js:29:5)
    at DestroyableTransform.Transform._read (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/path/node_modules/gulp-bump/node_modules/readable-stream/lib/_stream_writable.js:334:11)

我已经检查了 newVersionhash 的所有值,它们都是有效的字符串。我错过了什么?

原来我必须 trim 来自 getHash() 函数的字符串

hash = getHash().trim();