4

for the last day im struggling to use a git repository as a component. i tried alot of approaches, and none of then worked when i type npm i

here is some approaches that i have tried:

npm install from Git in a specific version,

How to use private Github repo as npm dependency

Git repository to a dependency in package.json

Import component from a different repo

i created 2 rep in git hub:

main project => should consume the component

chocolate component => thats my component

every time i put this in my package.json (main project repo), i got that error:

"dependencies": {
   "test-component": "IgorEstevao/test-component#master", # try 1
   "test-component": "git://github.com/IgorEstevao/test-component.git#0.0.1", # try 2
   "test-component": "git://github.com/IgorEstevao/test-component.git", # try 3...
}

npm ERR! premature close

How i use chocolate component in main project?

keep in mind in the future booth repositories gonna be private, so i think i will need to use github api key to access?

R. Richards
  • 24,603
  • 10
  • 64
  • 64
Igor
  • 399
  • 4
  • 18

2 Answers2

3

You appear to have an error in your JSON. JSON does not allow trailing commas. This is very annoying.

Remove the last comma from your dependency object.

"dependencies": {
   "test-component": "IgorEstevao/test-component#master", # try 1
   "test-component": "git://github.com/IgorEstevao/test-component.git#0.0.1", # try 2
   "test-component": "git://github.com/IgorEstevao/test-component.git", # try 3...
}                                                                     ^
                                                                      |
                                                                      |
                                                                remove this

I'm not very familiar with NPM, but having three different values for the same key is unlikely to be valid.


If you wish to use a Github repository as an NPM dependency, follow the Github instructions as well as the NPM instructions.

As of version 1.1.65, you can refer to GitHub urls as just “foo”: “user/foo-project”. Just as with git URLs, a commit-ish suffix can be included.

To depend on the master branch of the IgorEstevao/test-component repository...

"dependencies": {
  "test-component": "IgorEstevao/test-component#master"
}

No trailing comma.

Schwern
  • 153,029
  • 25
  • 195
  • 336
1

You should keep all your files in the project root directory instead of wrapping them in my-cool-component.

Wenhan Wu
  • 96
  • 2