无法使 libphonenumber npm 包正常工作,fs.readFileSync 不是函数错误
Cannot get the libphonenumber npm package working, fs.readFileSync is not a function error
我正在尝试使用 googlei18n libphonenumber library 进行 phone 号码验证。我通过 npm i libphonenumber
使用 npm 包,但是当我这样做时:
var libphonenumber = require('libphonenumber')
我收到错误 Uncaught TypeError: fs.readFileSync is not a function
即使我将 browserify-fs
添加为 dep 并在 libphonenumber
之前要求它,我仍然会收到错误。我一直在谷歌上搜索并且无法弄清楚这个错误甚至意味着什么,真的,除了它是某种目录功能。 libphonenumber
不应该是脚本,不是文件目录吗?
如有任何帮助,我们将不胜感激!
您安装的模块明确是 Google 代码 到节点 的端口,不适用于浏览器。如果你想在浏览器中使用它,请不要从 npm 安装它,而是直接从 Google 的存储库下载它。如果您想将它与 browserify 一起使用,请查看 browserify-shim,它允许您捆绑不使用 CommonJS 模块的库。
我正在尝试使用 googlei18n libphonenumber library 进行 phone 号码验证。我通过 npm i libphonenumber
使用 npm 包,但是当我这样做时:
var libphonenumber = require('libphonenumber')
我收到错误 Uncaught TypeError: fs.readFileSync is not a function
即使我将 browserify-fs
添加为 dep 并在 libphonenumber
之前要求它,我仍然会收到错误。我一直在谷歌上搜索并且无法弄清楚这个错误甚至意味着什么,真的,除了它是某种目录功能。 libphonenumber
不应该是脚本,不是文件目录吗?
如有任何帮助,我们将不胜感激!
您安装的模块明确是 Google 代码 到节点 的端口,不适用于浏览器。如果你想在浏览器中使用它,请不要从 npm 安装它,而是直接从 Google 的存储库下载它。如果您想将它与 browserify 一起使用,请查看 browserify-shim,它允许您捆绑不使用 CommonJS 模块的库。