无法获取libphonenumber npm包工作,fs.readFileSync不是一个函数错误

我正在尝试使用googlei18n的libphonenumber库进行电话号码validation。 我通过npm i libphonenumber使用npm包,但是当我这样做:

 var libphonenumber = require('libphonenumber') 

我得到错误Uncaught TypeError: fs.readFileSync is not a function

即使我将browserify-fs作为dep并在libphonenumber之前libphonenumber ,我仍然会得到这个错误。 我一直在search,不知道这个错误甚至意味着,除了它是某种目录function。 libphonenumber不应该是一个脚本,而不是一个文件目录?

任何帮助将不胜感激!

您已经安装的模块显式是Google代码的端口,而不是浏览器。 如果你想在浏览器中使用它,不要从npm安装它,而是直接从Google仓库下载它。 如果你想在browserify中使用它,请看一下browserify-shim ,它允许你捆绑那些不使用CommonJS模块的库。

另见https://github.com/mattbornski/libphonenumber/issues/17