8

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?
Rodrigo
  • 5,435
  • 5
  • 42
  • 78
  • Can you post your package.json and `npm -v`? I just tried the suggestion of @Chris911 and the package was successfully installed. – philsch Dec 29 '15 at 16:38
  • The error that Rodrigo mentioned will occur during run time and not during ```npm install``` command. The error occurred at ```require('rc-slider')```. The problem was with the package.json. As this project is a ```reactjs``` project, it must be compiled when installed from github. – Anand S Dec 29 '15 at 18:25

2 Answers2

4

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.

Anand S
  • 1,068
  • 9
  • 22
2

You can use git repositories as NPM packages:

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

Chris911
  • 4,131
  • 1
  • 23
  • 33