Catfish
Catfish

Reputation: 19304

How to reference dependency installed globally on computer?

I'm building a package (let's call it project a) that i'm trying to include in another project (project b).

In project b, I have this in my package.json

...
"dependencies": {
    "a": "C:\\Users\\myuser\\AppData\\Roaming\\npm\\node_modules\\a"
  },
...

but when I run npm install in project b, I get the error:

npm ERR! notarget No compatible version found: 1@'C:\Users\myuser\AppData\Roaming\npm\node_modules\a'
npm ERR! notarget Valid install targets:
npm ERR! notarget ["1.0.0","1.0.1","1.0.2","1.0.3","1.0.4","1.0.5","1.0.6"]

Versions 1.0.0 - 1.0.6 are published (although don't work).

Why doesn't npm install look at the path that I specified instead of looking in the NPM public repo?

Upvotes: 0

Views: 1727

Answers (2)

Catfish
Catfish

Reputation: 19304

I was able to install my locally built dependency by running npm install C:\Users\myuser\AppData\Roaming\npm\node_modules\a in the project that I wanted to consume the dependency.

Upvotes: 0

Ry-
Ry-

Reputation: 225124

Because that’s not a type of source that npm recognizes. See package.json(5):

dependencies
       Dependencies are specified with a simple hash of package name  to  ver‐
       sion  range.  The  version  range  is  a  string  which has one or more
       space-separated descriptors.  Dependencies can also be identified  with
       a tarball or git URL.

       Please  do  not  put test harnesses or transpilers in your dependencies
       hash.  See devDependencies, below.

       npm help  See semver for more details about specifying version ranges.

       ·   version Must match version exactly

       ·   >version Must be greater than version

       ·   >=version etc

       ·   <version

       ·   <=version

       ·   npm help   ~version  "Approximately  equivalent  to  version"   See
           semver

       ·   npm help  ^version "Compatible with version"  See semver

       ·   1.2.x 1.2.0, 1.2.1, etc., but not 1.3.0

       ·   http://... See 'URLs as Dependencies' below

       ·   * Matches any version

       ·   "" (just an empty string) Same as *

       ·   version1 - version2 Same as >=version1 <=version2.

       ·   range1 || range2 Passes if either range1 or range2 are satisfied.

       ·   git... See 'Git URLs as Dependencies' below

       ·   user/repo See 'GitHub URLs' below

Run npm link inside C:\Users\myuser\AppData\Roaming\npm\node_modules\a instead and set a regular dependency in your package.json.

Upvotes: 1

Related Questions