【问题标题】:Browserify: replace local file with NPM module using 'browser' field in 'package.json'Browserify:使用“package.json”中的“browser”字段将本地文件替换为 NPM 模块
【发布时间】:2015-11-18 03:51:11
【问题描述】:

我正在尝试浏览具有大量依赖项的复杂库。 其中一个库需要使用 NPM 模块切换本地文件。 我将“浏览器”字段添加到该库的“package.json”中,内容如下:

{
  "./lib/local_file.js": "npm_module_name"
}

然后在我需要这个库的代码上运行 browserify。 结果,我看到以下错误:

Error: ENOENT: no such file or directory, lstat '/home/user/dev/my-project-dir/npm_module_name'
    at Error (native)

作为临时解决方案,我创建了“local_file_browser.js”文件:

module.exports = require('npm_module_name').exports

并将“浏览器”字段更改为:

{
  "./lib/local_file.js": "./lib/local_file_browser.js"
}

一切正常,但如果可以避免的话,我宁愿不创建包装文件。有可能吗?

附:如果有帮助,我将我的代码推送到 Github https://github.com/APIs-guru/jsonpath/blob/master/package.json#L16-L18 我试图浏览的项目是这个https://github.com/lucybot/api-spec-converter 它依赖于一些库,而这些库又依赖于 'jsonpath' 库。

【问题讨论】:

    标签: node.js browserify package.json


    【解决方案1】:

    这是 browserify 中的一个错误,它已经修复: https://github.com/substack/node-browserify/issues/1435

    【讨论】:

      猜你喜欢
      • 2016-02-01
      • 1970-01-01
      • 2016-06-14
      • 1970-01-01
      • 1970-01-01
      • 2021-03-23
      • 1970-01-01
      • 1970-01-01
      • 2015-06-06
      相关资源
      最近更新 更多