Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js - NPM pacakge publish locally and install the locally published NPM package for a Node.js application

Tags:

node.js

npm

I have created a local NPM pacakge, i am trying to install the local package using fallowing command "npm install ../replacevalue/replacevalue-0.1.1tgz".

This is giveing me fallowing error. My agenda is to "Locally test my npm modules without publishing them to npmjs.org".

0 info it worked if it ends with ok
    1 verbose cli [ 'D:\\Program Files\\nodejs\\\\node.exe',
    1 verbose cli   'D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
    1 verbose cli   'install',
    1 verbose cli   '../replacevalue/replacevalue-0.1.1tgz' ]
    2 info using [email protected]
    3 info using [email protected]
    4 verbose node symlink D:\Program Files\nodejs\\node.exe
    5 verbose readDependencies using package.json deps
    6 verbose cache add [ '../replacevalue/replacevalue-0.1.1tgz', null ]
    7 verbose cache add name=undefined spec="../replacevalue/replacevalue-0.1.1tgz" args=["../replacevalue/replacevalue-0.1.1tgz",null]
    8 verbose parsed url { protocol: null,
    8 verbose parsed url   slashes: null,
    8 verbose parsed url   auth: null,
    8 verbose parsed url   host: null,
    8 verbose parsed url   port: null,
    8 verbose parsed url   hostname: null,
    8 verbose parsed url   hash: null,
    8 verbose parsed url   search: null,
    8 verbose parsed url   query: null,
    8 verbose parsed url   pathname: '../replacevalue/replacevalue-0.1.1tgz',
    8 verbose parsed url   path: '../replacevalue/replacevalue-0.1.1tgz',
    8 verbose parsed url   href: '../replacevalue/replacevalue-0.1.1tgz' }
    9 silly lockFile 11fd2abd-placevalue-replacevalue-0-1-1tgz ../replacevalue/replacevalue-0.1.1tgz
    10 verbose lock ../replacevalue/replacevalue-0.1.1tgz C:\Users\mgowd1\AppData\Roaming\npm-cache\11fd2abd-placevalue-replacevalue-0-1-1tgz.lock
    11 silly lockFile 11fd2abd-placevalue-replacevalue-0-1-1tgz ../replacevalue/replacevalue-0.1.1tgz
    12 silly lockFile 11fd2abd-placevalue-replacevalue-0-1-1tgz ../replacevalue/replacevalue-0.1.1tgz
    13 error addLocal Could not install ../replacevalue/replacevalue-0.1.1tgz
    14 error Error: ENOENT, stat 'C:\node\replacevalue\replacevalue-0.1.1tgz'
    15 error If you need help, you may report this log at:
    15 error     <http://github.com/isaacs/npm/issues>
    15 error or email it to:
    15 error     <[email protected]>
    16 error System Windows_NT 6.1.7601
    17 error command "D:\\Program Files\\nodejs\\\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "../replacevalue/replacevalue-0.1.1tgz"
    18 error cwd C:\node\Node_Odin
    19 error node -v v0.10.22
    20 error npm -v 1.3.14
    21 error path C:\node\replacevalue\replacevalue-0.1.1tgz
    22 error code ENOENT
    23 error errno 34
    24 verbose exit [ 34, true ]
like image 592
Manu Avatar asked Jan 21 '14 03:01

Manu


People also ask

How install npm local packages?

Example: Let the local-dir is the local directory and project-dir is the project directory and local_module is the local module package you want to install, first go to the local-dir and type npm link and next go to the project directory and type npm link <local_module> this will link your local module to your project.

Should I install npm packages globally or locally?

It's best to install locally when relying on a package from your module, such as Node. js. This is how npm install works by default. The grunt CLI package, for example, must be installed globally before it can be used as a command-line tool.


3 Answers

You want to be using npm link.

npm link allows you to 'install' a directory on your filesystem as if it were a package. It creates a symbolic link, meaning that you only have to run it once for the package to always stay 'up to date'.

To use it, navigate into the project you'd like to use your new package in, and run npm link /some/directory/path/to/your/package.

like image 75
Zack Bloom Avatar answered Oct 23 '22 21:10

Zack Bloom


For testing you can just run "npm install " from your main package folder. It will install your local package as dependency to the node_modules folder. Then you can run "npm install" to install other dependecies.

like image 26
Dr.Crazy Avatar answered Oct 23 '22 21:10

Dr.Crazy


If your still looking for an answer, these are the steps I took to get it working using help from a few answers:

cd my-package
npm run build
cp package.json dist/package.json
cd dist
npm link

cd my-project
npm link my-package-name
// Once you check your node_modules you should now see the correct dist files

If you made any mistakes allong the way, or already tried link you can remove by:

cd my-project
npm unlink my-package-name
like image 1
Gavin Avatar answered Oct 23 '22 22:10

Gavin