【问题标题】:syntaxhighlighter - Building: loadReposFromCache(...).error is not a functionsyntaxhighlighter - 构建:loadReposFromCache(...).error 不是函数
【发布时间】:2017-11-22 15:45:53
【问题描述】:

我正在尝试使用插件SyntaxHighlighter v4,但我无法让构建过程正常工作!

按照here 的说明,我收到以下错误:

$ ./node_modules/gulp/bin/gulp.js setup-project
[10:12:20] Requiring external module babel-register
[10:12:20] Using gulpfile C:\git\syntaxhighlighter\gulpfile.babel.js
[10:12:20] Starting 'setup-project:clone-repos'...
[10:12:20] 'setup-project:clone-repos' errored after 1.96 ms
[10:12:20] TypeError: loadReposFromCache(...).error is not a function
    at loadRepos (C:/git/syntaxhighlighter/build/setup-project.js:39:48)
    at Gulp.<anonymous> (C:/git/syntaxhighlighter/build/setup-project.js:48:5)
    at module.exports (C:\git\syntaxhighlighter\node_modules\orchestrator\lib\runTask.js:34:7)
    at Gulp.Orchestrator._runTask (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:273:3)
    at Gulp.Orchestrator._runStep (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:214:10)
    at Gulp.Orchestrator.start (C:\git\syntaxhighlighter\node_modules\orchestrator\index.js:134:8)
    at C:\git\syntaxhighlighter\node_modules\gulp\bin\gulp.js:129:20
    at _combinedTickCallback (internal/process/next_tick.js:67:7)
    at process._tickCallback (internal/process/next_tick.js:98:9)
    at Module.runMain (module.js:606:11)
(node:2532) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: ENOENT: no such file or directory, open 'C:\git\syntaxhighlighter\.projects-cache.json'

似乎没有将 github 存储库文件导入/repos/ 目录。我可以以某种方式手动执行此操作吗?还有另一种方法可以构建它以便我可以使用它吗?或者甚至像在 v3 中一样找到构建的文件?

这是 build/setup-project.js 中失败的函数

gulp.task('setup-project:clone-repos', 'Clones all repositories from 
  SyntaxHighlighter GitHub organization', () =>
    loadRepos()
      .then(R.filter(repo => !fs.existsSync(pathToRepo(repo))))
      .then(R.filter(repo => repo.name !== 'syntaxhighlighter'))
      .then(R.map(R.curry(cloneRepo)))
      .then(Promise.all)
);

回溯我们看到:

const loadReposFromCache = () => fs.readFile.promise(REPOS_CACHE, 'utf8').then(JSON.parse);
const loadRepos = () => loadReposFromCache().error(loadReposFromGitHub).then(R.map(R.pick(['clone_url', 'name'])));

function loadReposFromGitHub() {
  const request = require('request');

  const opts = {
    url: 'https://api.github.com/orgs/syntaxhighlighter/repos?per_page=300',
    json: true,
    headers: { 'User-Agent': 'node.js' },
  };

  return new Promise((resolve, reject) =>
    request(opts, (err, response) => {
      if (err) return reject(err);
      const json = response.body;
      fs.writeFile(REPOS_CACHE, JSON.stringify(json, null, 2));
      resolve(json);
    })
  );
}

【问题讨论】:

  • 您找到解决方法了吗?我面临同样的问题。谢谢。
  • @vaibhav 我只是使用了一个不同的插件。 Prism.js 很适合我。
  • 我最终做了同样的事情:)

标签: javascript plugins gulp


【解决方案1】:

该项目的构建代码中有几个问题。

对于这里的具体问题,Bluebird promise 上的 Songbird 包装器似乎不再匹配 - 因此“.error 不是函数”(在 songbird 上,但在 bluebird 上没问题)。

所以将.error 替换为.catch 或将require('songbird') 替换为require('bluebird')

无论哪种情况,这只是构建问题的开始......

无论如何,我已将此添加到项目的问题跟踪中,但这是我为使其成为 buiid 所做的工作: https://github.com/karljacuncha/syntaxhighlighter/commit/dc015fa299d4d249e8518664e205a838c55372cf

【讨论】:

  • 这个语法高亮项目有替代方案吗?也许它提供了一个直接的 JS 文件包,我可以从网页中引用,而不必与过度设计的构建过程抗衡?
  • @JonathanNeufeld 你可以从bartjolling.github.io/2021/04/29/syntaxhighlighter-online.html下载它们
  • @BartJolling 这太棒了!我设法让语法突出显示在我的网站上再次工作,谢谢!
【解决方案2】:

构建再次中断(2021 年 4 月)。我从karljacuncha's answer 分叉了项目并将fs.writeFile 的调用更改为fs.writeFileSync

https://github.com/BartJolling/syntaxhighlighter/commit/7dbd08203cba8ef3be72cbe1abbfb3475be19ef4

我还包含了我在更大的社区中找到的其他修复,我还修复了 -output 参数的使用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-22
    • 2018-07-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多