cb函数

阅读: 评论:0

cb函数

cb函数

cb函数

I regularly use Gitbook, a little Node.js software used to generate an ebook from a set of markdown files.

我经常使用Gitbook ,这是一个小的Node.js软件,用于从一组markdown文件生成电子书。

I use it for my ebooks. Today I was trying to generate a PDF, running gitbook pdf ., when I got a really weird error:

我将其用于电子书。 今天,我试图生成一个运行gitbook pdf . ,当我遇到一个非常奇怪的错误时:

➜  ebook git:(master) ✗ gitbook pdf .
/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287if (cb) cb.apply(this, arguments)^TypeError: cb.apply is not a functionat /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js:287:18

cb.apply is not a function. What does this even mean? And most importantly, why do I have this error now? I didn’t update the gitbook package recently, and I didn’t… Oh I think I updated the Node.js version I run. But I have no idea why this should be the problem. Maybe it is.

cb.apply is not a function 。 这到底是什么意思? 而最重要的是,我现在为什么有这样的错误? 我最近没有更新gitbook软件包,也没有……哦,我想我更新了我运行的Node.js版本。 但是我不知道为什么这应该是问题。 也许是。

Anyway.. the error comes from the /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js file. This is the graceful-js npm package, a “drop-in replacement for the built-in Node.js fs module, making various improvements”, installed over 33 million times a week.

无论如何,该错误来自/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js文件。 这是graceful-js npm软件包 ,它是“内置Node.js fs模块的直接替代品,进行了各种改进”,每周安装超过3,300万次。

One of those improvements seems to break my workflow, today!

今天,这些改进之一似乎破坏了我的工作流程!

I don’t have a lot of time free to find out why my Node.js version gives problems with this application I didn’t create and this library.

我没有很多时间来找出为什么我的Node.js版本会给我没有创建的这个应用程序和这个库带来问题。

I opened the file /usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js, where the error comes from.

我打开了文件/usr/local/lib/node_modules/gitbook-cli/node_modules/npm/node_modules/graceful-fs/polyfills.js ,该错误来自哪里。

Here’s the function that gives the problem:

这是给出问题的函数:

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

This seems to fix something in older version of Node.js.. it shouldn’t be needed for me.

这似乎修复了旧版本的Node.js中的某些问题。对我来说,它不是必需的。

I see it’s being used in lines 62-64 of the same file:

我看到它在同一文件的第62-64行中使用:

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

I commented out those lines:

我注释了以下几行:

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

and everything worked fine, I was able to run the gitbook command again, and I got my nice PDF.

并且一切正常,我能够再次运行gitbook命令,并且得到了不错的PDF。

翻译自: /

cb函数

本文发布于:2024-02-01 04:49:20,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170673416233982.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:函数   cb
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23