MostlyAdequate / mostly-adequate-guide

Mostly adequate guide to FP (in javascript)
Other
23.39k stars 1.86k forks source link

Errors prevent pdf generation #602

Open AaronLain opened 3 years ago

AaronLain commented 3 years ago

Just wanted to leave this here in case anyone else is having this problem. I came across this error when attempting to turn this book into a pdf. When I ran npm run setup I received this error:

/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:278
      if (cb) cb.apply(this, arguments)
                 ^

TypeError: cb.apply is not a function

I went to the specified file and found the problematic function.

function statFix (orig) {
  if (!orig) return orig
  // Older versions of Node erroneously returned signed integers for
  // uid + gid.
  return function (target, cb) {
    return orig.call(fs, target, function (er, stats) {
      if (!stats) return cb.apply(this, arguments)
      if (stats.uid < 0) stats.uid += 0x100000000
      if (stats.gid < 0) stats.gid += 0x100000000
      if (cb) cb.apply(this, arguments)
    })
  }
}

What it does, as far as I can tell, is manage some type quirks with older versions of node. In my file, it was called three times up above on lines 62-64.

fs.stat = statFix(fs.stat)
fs.fstat = statFix(fs.fstat)
fs.lstat = statFix(fs.lstat)

I just commented out those lines and was able to install. Once I installed Calibre (brew install --cask calibre) I was able to successfully generate the pdf. As long as you have a recent version of node.js installed, this solution should work. All credit to Flaviocopes for the solution.

dotnetCarpenter commented 3 years ago

@AaronLain Thanks!

For installing Calibre on Linux (also WSL2) see https://calibre-ebook.com/download_linux

I get some errors, like:

├── gitbook-plugin-exercises@3.0.1  invalid (git+https://github.com/MostlyAdequate/plugin-exercises.git#6eb1211ea13fb5731930ff7883d38efe7a743609)
└─┬ gitbook-plugin-include-codeblock@3.1.2  invalid

But book.pdf looks alright to me :)