Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import package installed from github

I just installed a package that is not in npm registry via github like this

yarn add git+https://github.com/azazdeaz/react-color-picker-wheel.git

Now I can see it in my package.json file like this

"react-color-picker-wheel": "git+https://github.com/azazdeaz/react-color-picker-wheel.git"

However when I import it like this

import ColorPickerWheel from 'react-color-picker-wheel'

I get this error Uncaught Error: Cannot find module 'react-color-picker-wheel'

like image 520
Hayk Safaryan Avatar asked Jul 19 '17 13:07

Hayk Safaryan


People also ask

How do I import something from GitHub?

In the upper-right corner of any page, click , and then click Import repository. Under "Your old repository's clone URL", type the URL of the project you want to import. Choose your personal account or an organization to own the repository, then type a name for the repository on GitHub.

How do I import existing Git repository?

Select Repos, Files. From the repo drop-down, select Import repository. If the source repo is publicly available, just enter the clone URL of the source repository and a name for your new Git repository.


1 Answers

The main property of the package.json in the Github repo is set to ./lib/index.js but that file does not exist in the repository.

When you import that module, it tries to resolve the file ./lib/index.js relative to the node_modules/react-color-picker directory.

You could submit a PR to update the package.json's main property to refer to the correct file (./src/index.js, or fork the repository and update the Github url to your repo's URL. It's worth checking out the NPM docs about the main property as well :)

https://docs.npmjs.com/files/package.json#main

like image 56
Niekert Avatar answered Oct 10 '22 09:10

Niekert