What is the process for transferring npm package files to my local project?

Despite my efforts to find the answer, I couldn't locate it and so here I am asking again.

What I'm looking for:

I need to move a file from node_modules to my project in order to work on it.

First attempt:

I moved the file I wanted to edit And adjusted the import path accordingly https://i.stack.imgur.com/mFiIE.png https://i.stack.imgur.com/Z3znx.png

Outcome:

Puzzling situation:

All modified paths seem correct I can access the imported file through the path in the IDE.

Sample repository:

https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1 In particular: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal1/src/components/editableText

Second attempt:

I transferred all imported files along with the one I want to modify into the project.

Outcome:

My thoughts: This issue might be related to Typescript or commonjs, but I'm unsure how to resolve it.

Sample repository: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2 Especially: https://github.com/YahngSungho/dfsfdsfsfdsfwfsd/tree/help/npmToLocal2/src/components/list/editableText/components/editable-text

If anyone has a solution to this problem, I would greatly appreciate your help.

Answer №1

Here are a few ways you can handle the situation:

Option 1: Take matters into your own hands and monkey-patch the module yourself:

Here's a general guide on how to do it:

Create a new file named ModifiedEditableText.tsx

Then in that file:

import { EditableText } from "@blueprintjs/core";

const newModule = {};

// Start by copying all fields from the original module
for (let fieldName in EditableText) {
    newModule[fieldName] = EditableText[fieldName];
}

// Write new implementations for any functions you want to change
newModule.function1 = function(arg, arg2, arg3) {
    // New function implementation
    // To call the original function, use:
    EditableText.function1();
}

export default newModule;

Option 2: Fork the module, make your changes, submit a PR, and hope for the best (though it may not get merged)

Option 3: Fork the module, implement your changes, and use that customized version in your code instead of the official library

Option 4: Utilize a library to monkey patch your component – here are some examples:

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

Error encountered while retrieving data from Firebase and storing it in an array within an IONIC application

I am currently working on a function that retrieves data from Firebase's real-time database and stores it in an array for mapping in React. However, I am encountering a TypeScript error that I'm having trouble resolving. The error message reads ...

ng-repeat not functioning properly with FileReader

Here is a look at how my view appears: <body ng-controller="AdminCtrl"> <img ng-repeat="pic in pics" ng-src="{{pic}}" /> <form ng-submit="postPic()"> <input id="photos" type="file" accept="image/*" multiple/> <button> ...

Implementing the onClick function for the correct functionality in a ReactJS map component

I have designed a mockup and now I am trying to bring it to life by creating a real component. View my component mockup here Starting with something simple, I created 3 buttons and an array. However, when I click on any button, all features are displayed ...

What is the reason behind the delayed mutation of the state when invoking the setState method in React?

Currently diving into the Forms section within the documentation of ReactJS. Just implemented this code snippet to showcase the use of onChange (JSBIN). var React= require('react'); var ControlledForm= React.createClass({ getInitialState: f ...

Ways to halt streaming without shutting down the Node.js server

I am currently facing an issue with closing a Twitter stream, as it causes my server to crash and requires a restart. Is there a way to close the stream without affecting the Nodejs (express) server? Here is the error message I am encountering: file:///mnt ...

Looping through color transitions upon hover using CSS

I am trying to create a color transition effect on hover, where the background changes from yellow to red and then back to yellow in a loop. I'm having trouble figuring out how to make this transition repeat continuously. Do I need to incorporate Java ...

Tips for creating an HTML page with the dimensions of an A4 paper sheet?

My goal is to display the HTML page in a browser while containing the content within the dimensions of an A4 size page. Additionally, when printed, the HTML page should be formatted to fit onto A4-sized paper pages. <div classNa ...

Top Method for Setting Up Node.js/npm without Using sudo

After researching the best way to install node.js/npm without requiring sudo for commands like npm install -g bower, I initially tried following this solution: Installing with nvm. However, installing it into the user's home directory may not be ideal ...

Struggling three.js newcomer faced with initial hurdle: "Function is undefined"

I am encountering a similar issue to the one discussed in this question: Three.js - Uncaught TypeError: undefined is not a function -- and unfortunately, the solutions provided there did not work for me. My journey with three.js began on the Getting Start ...

Sending an HTTP request from within an Express/Node.js application

I am currently in the process of setting up an express service for a program I am developing. The goal is to interact with an external API, retrieve the data, and store it in a MongoDB database that I have already set up. While this task may seem straight ...

Display an alert when no matches are found in autocomplete suggestions

I am implementing the code below to populate a textbox with data. If I input a, all records starting with a are displayed in the dropdown from the database. However, if I input a value that does not exist in the database, there is no message like "No Recor ...

Can you please explain to me the purpose of the ncu -u command?

Struggling to update my Angular project in Visual Studio to a specific version of Angular. Instead of following the tutorial that provided me with the latest Angular version, I wanted to install version 6 specifically. So, I ran npm install -g @angular/ [ ...

Check the schedule for any upcoming events

I am currently designing a website for a friend and I have a question regarding the functionality of the FullCalendar jQuery plugin. Is there a way to determine if there is an event scheduled for today using FullCalendar? If so, I would like to display t ...

Encountering a problem during the installation of node-inspector

Yesterday, I encountered a frustrating npm issue that has me stuck. When running the command npm --version, an error is returned stating 'CALL "C:\Program Files\nodejs\\node.exe" "C:\Program Files\nodejs\\no ...

The TypeScriptLab.ts file is generating an error message at line 23, character 28, where it is expecting a comma

I am attempting to convert a ts file to a js file. My goal is to enter some numbers into a textarea, and then calculate the average of those numbers. However, I encountered an error: TypeScriptLab.ts(23,28): error TS1005: ',' expected. I have in ...

What is the best way to determine the number of characters that will fit within the width of the document?

I am looking to create a JavaScript function using jQuery that can determine the number of characters that will fit in a single line within the browser window. While I am currently utilizing a monospace font for simplicity's sake, I would like to adap ...

Any advice on resolving the issue of "Failed to parse source map from..." errors in my ReactJS/TS project?

I am working on a ReactJS project and encountered an issue while trying to implement a Barcode-Scanner npm module called html5-qrcode. The error message I keep receiving is: Failed to parse source map from 'C:\...\node_modules\html5-qr ...

Unable to process form submission using Ajax in ASP.NET MVC

I'm having trouble with submitting a form using ajax and opening a modal dialog after the ajax function is successful. Whenever I click the submit button, the process doesn't complete. Where could the issue be, in the ajax method or somewhere el ...

"An error has occurred stating that the function Factory.function() in AngularJS

I'm a beginner with AngularJS and could use some assistance! My issue involves retrieving JSON data from a URL in a factory function and returning it to the controller. However, I keep getting an error stating that the function doesn't exist. Wh ...

Retrieving the class name using jQuery

In my HTML code, there is a div with three classes defined as: <div class = "a b c"> .. </div> My goal is to access only the class b using the .attr() method. Is this achievable? ...