Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use modified node module using github branch?

I'm using the rc-slider component in my application and had to add one feature to meet my needs.

I forked the main repository and pushed my changes to this branch.

In the application, I changed the package.json as below and ran the npm install again:

"rc-slider": "Rodrigora/slider#add-label"

Nothing changed. Seems that npm doesn't update the dependencies.

So, I removed the node_modules and rails cache folder and ran the install command again:

rm -rf node_modules/
rake tmp:cache:clear
npm install

Now, I have this error:

events.js:142
      throw er; // Unhandled 'error' event
      ^

Error: Cannot find module 'rc-slider' from '/Users/rodrigora/project/app/assets/javascripts'

NPM can't find the rc-slider when I using the modified branch.

  • NPM does not update the dependencies only changing the package.json file?
  • Should I run some build command to install my branch code?
like image 566
Rodrigo Avatar asked Dec 20 '15 23:12

Rodrigo


People also ask

Can you modify node modules?

You can use patch-package to make and persist changes to node modules. This can be done by first making changes to the package inside node_modules and then running the following command, with <package name> being the name of the package you just made changes to.

How do I point a json package to a branch?

Open package. json , to to the "devDependencies" or "dependencies" key and add your package in the following format: "package-name": "username/repo#branch-name", And then install the package with npm install or yarn .

Should I include node_modules in GitHub?

You should not include folder node_modules in your . gitignore file (or rather you should include folder node_modules in your source deployed to Heroku). If folder node_modules: exists then npm install will use those vendored libraries and will rebuild any binary dependencies with npm rebuild .


1 Answers

In npm docs:

"dependencies": {
  "rc-slider": "git://github.com/Rodrigora/slider.git#add-label"
}

Also you can use

npm install git://github.com/Rodrigora/slider.git#add-label --save

The above command will add that dependency in your package.json.

Edit:

I miss understood your question. I tried the below fix in the repo that you mentioned and it worked. (you should also have the dependency setup like above)

It is a react project. It is compiled and published to NPM.

So, if you want to install it directly from your github fork, you should make some changes to package.json

Before making changes in package.json install rc-tools globaly:

sudo npm install rc-tools -g

Change the files that should be included:

"files": [
    "index.js",
    "assets",
    "src"
]

and add postinstall script in scripts:

"postinstall": "rc-tools run compile"

Then try installing from github after making these changes in that branch.

like image 176
Anand S Avatar answered Sep 19 '22 18:09

Anand S