【问题标题】:Manually adding method in a node module在节点模块中手动添加方法
【发布时间】:2015-08-28 17:34:47
【问题描述】:

我在我的网站上使用 material-ui,而在 npm 上找到的软件包与其最新版本(在 Github 上找到)已过期。我手动将这行代码添加到他们的主题管理器类中,这反映了更改:

setContentFontFamily(newContentFontFamily) {
  if (typeof newContentFontFamily !== "undefined" && newContentFontFamily !== null) {
    this.contentFontFamily = newContentFontFamily;
    this.component = Extend(this.component, this.template.getComponentThemes(this.palette, this.spacing));
  }
},

但是,我的应用程序没有注册这些更改,当我尝试设置字体时:

ThemeManager.setContentFontFamily('Open Sans, Roboto, sans serif');

控制台给了我这个错误:

Uncaught TypeError: ThemeManager.setContentFontFamily is not a function

我正在使用 Browserify 来捆绑我的客户端“需要”依赖项。这是 Browserify 问题,npm 问题,还是我不了解节点模块的工作原理?

编辑:这是我的package.json

{
  "name": "FooProject",
  "version": "0.0.0",
  "description": "",
  "dependencies": {
    "highlight.js": "^8.7.0",
    "material-ui": "callemall/material-ui",
    "react": "^0.13.3",
    "react-bootstrap": "^0.24.5",
    "react-highlight": "^0.5.0",
    "react-tap-event-plugin": "^0.1.7",
    "underscore": "^1.8.3"
  },
  "author": "Tina Zheng",
  "devDependencies": {
    "babelify": "^6.1.3",
    "bower": "^1.4.1",
    "browserify": "^11.0.1",
    "gulp": "^3.9.0",
    "gulp-react": "^3.0.1",
    "gulp-reactify": "^3.0.1"
  }
}

【问题讨论】:

    标签: javascript npm browserify node-modules material-ui


    【解决方案1】:

    您的问题的快速解决方案(除了联系作者并要求他们更新 npm)是使用存储库 url 作为依赖项而不是 npm 模块:

    git://github.com/user/project.git#commit-ish
    

    如果存储库在 GitHub 上,您可以使用缩写形式:

    "dependencies": {
        "express": "visionmedia/express",
        "mocha": "visionmedia/mocha#4727d357ea"
      }
    

    (docs)

    如果你只是直接编辑依赖,每次重建时它们都会被覆盖。

    【讨论】:

    • 我需要对我的 require 语句进行任何更改吗?卸载material-ui并使用Gi​​thub链接重新安装后,我的构建过程找不到'material-ui'
    • @TinaS.Zheng 不需要更改您的代码。你能用package.json 编辑你的问题吗?
    • 已编辑!我更改的行是"material-ui": "callemall/material-ui"
    • @tinazheng 看起来确实正确...更改后您运行npm update 了吗?它会抛出任何错误吗?
    • 我确实在更改后运行了npm update,但同样的错误也出现在我身上。我手动删除了material-ui节点包并通过npm重新安装,这次成功了。非常感谢!
    猜你喜欢
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-27
    • 2020-11-23
    相关资源
    最近更新 更多