2

I am trying to consume a private React NPM package from my own github repo. I have successfully published to my github repo the package.

In the consumer project, I have sucessfully installed the package using the command my github/packages page provided. Command line tells me it has added the package.

I add to App.js:

import { HelloWorld } from '<the-same-package-name/inside-the-package.json>';

When I try to use the actual component, I keep getting the error: Module not found: Error: Can't resolve '@my_github/private-repo' in <my local path>

does anyone have any idea what on earth I am doing wrong? I have the .npmrc set up in the same level as package.json with:

//npm.pkg.github.com/:_authToken=<my auth token with read privileges>
registry=https://npm.pkg.github.com/<my repo>

Is this a problem with exporting components from React? Am I not pulling in the component the correct way?

I have spent over an hour on this and just do not understand what part I am missing.

J.R.
  • 91
  • 1
  • 4
  • Check if your package is installed in your project's `node_modules` folder. From the error message the you should have a folder called `node_modules/@my_github` and inside this folder is another folder called `private-repo`. If instead you just find a folder called `private-repo` then you are importing it wrong. – slebetman Jun 03 '22 at 02:57
  • What should be in thisnode_modules/@my_github? I have a directory which contains the package.json and readme, but no files or component directories. How do I publish to npm from the package folder to include the actual components? I feel like I haven't published the packages correctly – J.R. Jun 03 '22 at 03:14
  • You don't need to publish to npm if your package is private. That's usually only useful if you want to publicly publish your package (though the paid version of npm allows you to publish private repos - see:https://www.npmjs.com/products). You can npm install directly from your git repo, a URL to a tar.gz file, a folder on your hard disk etc. For example you can `npm install git@github.com:your_github/your_package.git` or you can `npm install ../../some/folder/on/your/PC` – slebetman Jun 03 '22 at 03:23
  • See the documentation for package.json file format to see what kind of dependencies npm supports: https://docs.npmjs.com/cli/v7/configuring-npm/package-json#dependencies – slebetman Jun 03 '22 at 03:25
  • I'm aware I can pull from the repo directly, but I'm trying to pull from a private npm package as a test run for both future client projects and as a basis for this modular project I am building – J.R. Jun 03 '22 at 04:12
  • So you already have a private module on npm? I'm a bit confused because npm does not have repos - that's not how they work - they have modules. Just like Apple App Store does no thave repos - they have apps. Yet when I showed you how you can install from repos directly you say you don't want to install from repos. What exactly are you trying to do? – slebetman Jun 03 '22 at 06:55
  • Did you ever solve this? I am having the same issue. Private Github repo with package published. All i get after install is the package.json and readme – andrew macnaughton Apr 06 '23 at 19:00

0 Answers0