npm install from tgz created with npm pack

I've created a .tgz file with npm pack. When trying to install it npm prints out the following error:

D:\tmp>npm install package-0.0.1.tgz
npm WARN saveError ENOENT: no such file or directory, open 'D:\tmp\package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open 'D:\tmp\package.json'
npm WARN tmp No description
npm WARN tmp No repository field.
npm WARN tmp No README data
npm WARN tmp No license field.

It looks like npm for some reason does not extract the contents of my .tgz package, meaning all the .js files, package.json etc. although everything is there. Apparently it only tries to install the dependencies listed in my package. Should it really work this way or I'm doing something wrong?

2 Answers

This error means you are not in a directory that has a package.json file and you are using the command that installs a package as a dependency into an existing, (local) npm project's package.json.

To install your package globally (just to test if it can be installed):

npm install -g package-0.0.1.tgz

Or, if you want to install/add it as a dependency to some other npm project (like a test harness), first make sure that npm project has a package.json, and then :

test-harness-dir> npm install package-0.0.1.tgz

Let's say you have the following project structure:

enter image description here

and you need to install core-1.2.7.tgz in the libs folder.

So you should run the following command in your project directory (test):

npm i ./libs/core-1.2.7.tgz

Once installed, your package.json file should look like below:

{ "name": "test", "version": "1.0.0", "description": "", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "author": "", "license": "ISC", "dependencies": { "@nolesh/core": "file:libs/core-1.2.7.tgz" <--- YOUR DEPENDENCY }
}

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like