Adding a method to a node module by hand

Working with my website, I've incorporated the material-ui package, but the version available on npm is outdated compared to the latest one on Github. To reflect these updates, I manually inserted this line of code into their Theme Manager class:

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

Despite making these changes, my application doesn't seem to recognize them when attempting to set a font:

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

Upon doing so, an error appears in the console:

Uncaught TypeError: ThemeManager.setContentFontFamily is not a function

I utilize Browserify for bundling client side 'require' dependencies. Could this issue be related to Browserify, an npm glitch, or is there a misunderstanding on how node modules operate?

Edit: Here's a snippet from my 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"
  }
}

Answer №1

An efficient way to address your issue (instead of reaching out to the authors for an npm update) is by using the repository URL as a dependency rather than the npm module:

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

If the repository is hosted on GitHub, you can utilize the shorter format:

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

(documentation)

Directly modifying the dependencies will result in them being overwritten whenever there's a rebuild.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Best practices for making an AJAX call to fetch information from a database

I have a database containing a single table. The table includes columns for Company and Time, among others, with Company and Time being crucial. Users can make appointments by filling out a form. Within the form, there are 2 <select> elements - one ...

The item holds significance, but when converted to a Uint8Array, it results in being 'undefined'

Hey there! I have a Uint8Array that looks like this: var ar = new Uint8Array(); ar[0] = 'G'; ar[1] = 0x123; The value at the second index is a hexadecimal number, and I want to check if ar[1] is greater than zero. So I wrote this code: if(ar[1 ...

How can we stop the jumping of images in the grid? Is there a way to eliminate the jump effect?

Here is a script I am working with: <script src="http://static.tumblr.com/mviqmwg/XyYn59y3a/jquery.photoset-grid.min.js"></script> <script> $(document).ready(function() { $('.photoset-grid').photose ...

Discover the geolocation data for post code 0821 exclusively in Australia using Google Maps Geocoding

I'm having trouble geocoding the Australian postcode 0821. It doesn't seem to reliably identify this postcode as being located within the Northern Territory, unlike 0820 and 0822 which work fine. Here's an example of what I'm doing: ...

Steps for updating text within an object in Angular

details = [ { event: "02/01/2019 - [Juan] - D - [Leo]", point: 72 }, { event: "02/01/2019 - [Carlo] - N - [Trish]", point: 92 } ]; I am attempting to modify the text within the titles that contain - N - or - D - The desired outcom ...

Issues with Jquery keyup on Android devices - unable to detect keyup

I have not tested this code on an iPhone, but I am certain (tested) that it does not work on Android mobile devices: $('#search').live('keyup',function(key){ if(key.which == 13){ /*ANIMATE SEARCH*/ _k ...

Tips for categorizing items retrieved from .getJSON based on their category property

Looking to display a menu of coffee items with their respective parent categories on the page? Here's how you can start: Category Title Item Item Item Item Category Title Item Item This is what my data model looks like: { "menuItems": [ ...

Guide to executing a fetch request prior to another fetch in React Native

I am currently working on a project using React Native. One issue I have run into is that all fetch requests are being executed simultaneously. What I actually need is for one fetch to wait until the previous one has completed before using its data. Speci ...

Potential causes for Chrome to send duplicate requests

In my nginx server logs, I have the following entries (IPs and paths altered for illustration purposes): 101.101.101.101 - - [15/Apr/2020:14:46:03 +0000] "GET /item/download-file/ready/5e971e290107e HTTP/2.0" 200 142940 "https://example.com/referer" "Mo ...

Check out the findings from a real-time generated collection of ajax requests

As I work on creating a dynamic array of ajax calls to be performed, I find myself faced with an intriguing challenge. Here's how I currently approach it: var requests = []; if (weNeedCustomerData) { var customerCallPromi ...

Creating a canvas with multiple label introductions can be achieved by following these

I am looking to group labels and sublabels on the x-axis of a canvas component. Currently, I only have sublabels like: RTI_0, RTI_1... I would like to add labels to these sublabels like: RTI = {RTI_0,RTI_1,RTI_2] BB = {BB_0, BB_1,BB_2,BB_3] <div cla ...

Facing an obstacle in Angular as I am unable to view my data

How can I bind the model of my controller in the init function and see the data when the init is called? Index.html <!DOCTYPE html> <html ng-app="I-Sign"> <head> <meta http-equiv='X-UA-Compatible' content='IE=edge&apo ...

The terminal greeted me with a message saying: "cdk: command not found" right after I had finished

I followed the installation instructions for AWS CDK from https://github.com/aws/aws-cdk After successfully running npm i -g aws-cdk, I encountered an issue when trying to execute cdk from the command line: $ cdk -bash: cdk: command not found Even after ...

Luxon: retrieve an array of time offsets and time zones (similar to what can be done in moment-timezone)

Currently, I am using the moment-timezone library to retrieve raw information for a specific timezone and then incorporating it directly into my downstream code. const zone = moment.tz.zone('Europe/London'); This data contains: { "name":"Eu ...

The absence of typings.json in Typescript is creating an issue

As of now, I am encountering the following error during compilation: typings.json is missing In my existing packages.json, I have included the following dependency: "devDependencies": { "typescript": "^2.6.1", ... } Do you have any suggestion ...

typescript makeStyles() functions from material-ui library

I've been struggling to find the correct type without relying on any. I have a working code that styles the component as expected: import { makeStyles } from '@material-ui/core/styles' const useStyles = makeStyles((theme) => ({ mainC ...

To add canvas to FreeBSD 10.1, run the command: `npm

Seeking help with this strange issue. Can anyone explain why cairo-1.12.18_1,2 is installed but setting export PKG_CONFIG_PATH=/usr/local/libdata/pkgconfig doesn't work? # uname -a FreeBSD test 10.1-RELEASE FreeBSD 10.1-RELEASE #0 r274401: Tue Nov 11 ...

Filtering a string array in Angular based on an object's value

I am facing a challenge with two arrays in my code. The first array, $scope.termini, contains strings, and the other one, $scope.reserved, contains objects. Each object in the second array has a variable called vrijemeTermina. My goal is to filter $scope.t ...

I am attempting to set up React, but I keep encountering an issue that says 'Error: EPERM: operation not allowed'

My attempts to set up React have been unsuccessful so far. Initially, I tried installing it using the command npx create-react-app ./, which did not work. Then, I attempted to run npm init react-app my-app, but unfortunately, that also failed. The error me ...

Utilizing Props to Manage State within Child Components

Is it possible to assign the props received from a Parent Component as the state of a Component? export default class SomeComp extends Component { constructor(props) { super(props); this.state = someProps; // <-- I want to set the ...