Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add local project dependency for npm install

Tags:

node.js

npm

What is the proper syntax to add local project dependency in npm package.json file?

I have git project locally in C:\projects\MyApp

I want to get this project with npm install. I tried following

"dependencies": {
  .....
  "my-app": "file://../projects/MyApp/MyApp.git"
  .....
 }

but getting error

Could not install ....

Any suggestion?

like image 566
αƞjiβ Avatar asked Mar 14 '23 02:03

αƞjiβ


2 Answers

Finally got it working

"my-app": "../projects/MyApp"

Its' simple until you know.

like image 148
αƞjiβ Avatar answered Mar 27 '23 12:03

αƞjiβ


Local dependency has to be a directory on your filesystem.


Alternately there is npm-link.

Excerpt from the docs:

Package linking is a two-step process.

First, npm link in a package folder will create a globally-installed symbolic link from prefix/package-name to the current folder (see npm-config for the value of prefix).

Next, in some other location, npm link package-name will create a symlink from the local node_modules folder to the global symlink.

Example:

cd ~/projects/node-redis    # go into the package directory
npm link                    # creates global link
cd ~/projects/node-bloggy   # go into some other package directory.
npm link redis              # link-install the package
like image 23
Rūdolfs Vikmanis Avatar answered Mar 27 '23 12:03

Rūdolfs Vikmanis