nikotromus
nikotromus

Reputation: 1054

Issue installing an npm package directly from Github

I have a React common project that I am trying to include in another React project (the 'base' project). I named the test project like so in the package.json file and committed it to Github:

{
  "name": "NPM-From-Git-Test",
  "version": "5.0.0",
  "description": "Trying to create a common React project and add it from github",
  "engines": {
    "npm": ">=3"
  },

Next I ran an npm install with the web address of the github project.

npm install git+https://myAddress/TestCommon

It installed and created a project folder in the node_modules folder named 'NPM-From-Git-Test'

Next I included the component 'ExamplePageOne' that I need in the 'base' project like so:

import {ExamplePageOne} from 'NPM-From-Git-Test';

The intellisense tells me that the 'NPM-From-Git-Test' Module is not installed, and when I start the dev server, I get the error 'Cannot resolve module 'NPM-From-Git-Test'.

What am I doing wrong?

Upvotes: 1

Views: 175

Answers (2)

Holly Cummins
Holly Cummins

Reputation: 11482

I found I got this error with npm 6, but upgrading to npm 7 resolved it.

Upvotes: 0

Nick Pierson
Nick Pierson

Reputation: 278

In NPM-From-Git-Test are you using export or export default to export ExamplePageOne? If you are using export default, you'll want to do:

import ExamplePageOne from 'NPM-From-Git-Test';

If you are using export, make sure that you are spelling ExamplePageOne exactly as you are in NPM-From-Git-Test's export.

More on ES6 imports and exports: http://exploringjs.com/es6/ch_modules.html

Upvotes: 1

Related Questions