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

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 ]


Solution 1:[1]

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.

Solution 2:[2]

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.

Solution 3:[3]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Zack Bloom
Solution 2 Dr.Crazy
Solution 3 Gavin