npm install from tgz created with npm pack - node.js

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?

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

Related

how to get the dependencies of a project with a package-lock.json but no package.json?

I have a project with a package-lock.json but no package.json.
When I run npm install I get the following:
npm WARN saveError ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/home/neubert/myproject/package.json'
npm WARN myproject No description
npm WARN myproject No repository field.
npm WARN myproject No README data
npm WARN myproject No license field.
up to date in 0.279s
found 0 vulnerabilities
Any ideas how I can make it so that the deps in the package-lock.json are downloaded, even if package.json isn't present?
Well my first thought would be to run
npm rebuild
If you have installed previously it will rebuild all the packages and they will print out on your screen. Then its just a matter of adding them back to a package.js
here is a link to npmjs.com and their cli commands... its handy. i have it bookmarked in my cheat sheets

Warnings when installing npm modules in project directories, but not when installing globally

I have observed this issue when installing both newsapi and RequireJS. The path to my project directory is as follow: Users\username\project
In my project directory, when I run npm install newsapi --save (installation instructions per the newsapi site or npm install requirejs (installation instructions per the RequireJS site, I get the following identical warnings:
npm WARN saveError ENOENT: no such file or directory, open 'C:\Users\username\project\package.json'
npm WARN enoent ENOENT: no such file or directory, open 'C:\Users\username\project\package.json'
npm WARN project No description
npm WARN project No repository field.
npm WARN project No README data
npm WARN project No license field.
It may be worth noting the project\node_modules\newsapi and project\node_modules\requirejs are still created and they seems to be populated as they should.
I noticed that when I install the modules globally (by running npm install -g newsapi --save or npm install -g requirejs) the installation succeeds without displaying any warnings. Why is this the case? What is happening in my project folder that might be causing this issue?
npm install fhqhwhgads will try to update the local project package.json but npm install -g fhqwhgads will install globally and so there's no package.json to update. So that's why you're note getting an warning with global installation.
If you want to create a package.json so that your dependencies can be tracked and replicated by others (or if you want to publish your code as a package), you can use npm init.

Module 'googleapis' is not listed as dependency in package.json

Step 1: I try to add googleapis as dependency and got the error
$ npm install googleapis
npm WARN saveError ENOENT: no such file or directory, open '[home]/package.json'
npm WARN enoent ENOENT: no such file or directory, open '[home]/package.json'
npm WARN saly No description
npm WARN saly No repository field.
npm WARN saly No README data
npm WARN saly No license field.
Question: Why is it looking for the file in my home directory as opposed to my project directory? Especially since I am making the call from my project directory.
Step 2: I misunderstood the error and proceeded to deploying my project and that's where I got the error
Module 'googleapis' is not listed as dependency in package.json
Step 3: I now try npm i googleapis --save but I still get the same errors as in steps 1 and 2.
It seems that the problem was due to that I forgot to cd into the functions directory before I tried to install the dependencies.

NPM "ENOENT: no such file or directory error" when installing Sails.js dependencies with Node 8.9.4 LTS

I recently upgraded my computer and with it, to the latest LTS version of Node and NPM:
Node.js 8.9.4
NPM 5.6.0
I have a Sails.js 0.12.14 application for which I'm trying to install NPM dependencies with npm install but when I do that, I get the following errors:
➜ web-service git:(feature/auth) ✗ npm install
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/package.json'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/README.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/LICENSE'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/index.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/pako-660dbb41/CHANGELOG.md'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/camelCase.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/uniqueId.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindKey.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unnest.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/bindAll.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/unset.js'
// a bunch of similar Lodash errors removed from here
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/T.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/zipWith.js'
WARN tar ENOENT: no such file or directory, open '/Users/Nag/Code/project/web-service/node_modules/.staging/lodash-6e6c9f2a/fp/lastIndexOfFrom.js'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: oauth-sign#0.8.2 (node_modules/oauth-sign):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/oauth-sign-b13c86db'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: mkdirp#0.5.1 (node_modules/mkdirp):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/mkdirp-c94c8047'
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: minimist#0.0.8 (node_modules/mkdirp/node_modules/minimist):
npm WARN enoent SKIPPING OPTIONAL DEPENDENCY: ENOENT: Cannot cd into '/Users/Nag/Code/project/web-service/node_modules/.staging/minimist-ba966a6e'
npm ERR! path /Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/#sailshq/body-parser
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall rename
npm ERR! enoent ENOENT: no such file or directory, rename '/Users/Nag/Code/project/web-service/node_modules/.staging/sails-02afd14e/node_modules/#sailshq/body-parser' -> '/Users/Nag/Code/project/web-service/node_modules/.staging/#sailshq/body-parser-6d1e8405'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Nag/.npm/_logs/2018-01-22T14_40_13_889Z-debug.log
I can't seem to figure out what's going on and can't find suitable answers anywhere else online. I even ran npm cache clean --force, rm -rf node_modules and retried with similar errors. It seemed to work fine when I was on Node ~6 but after upgrading to Node 8.9.4 and NPM 5.6.0, it just won't install my dependencies. How can I resolve this?
Try deleting the package-lock.json file.
For me, it turned out these errors were hiding the real underlying problem, which was that my credentials for a third-party npm repository (azure devops) had expired. I had to re-run vsts-npm-auth -config .npmrc to update the token in my .npmrc file.
No permission, no internet issue, it's just a general issue of npm.
I solved the problem with yarn.
yarn install
Or you can use no-optional flag.
npm install --no-optional
It may be a problem with the cache, try to verify the cache.
npm cache verify
In my case, I tried deleting package-lock.json, clearing and verifing the npm cache, removing node_modules, even stopping the antivirus (W10 machine) and was still getting this error.
I somehow fixed it by running npm update before npm install, which creates a new package-lock.json:
del /f package-lock.json
rd /s /q node_modules
npm cache clean
npm cache verify
npm update
npm install
Deleting and regenerating 'package-lock.json' usually solves this issue however that's inherently risky because you will likely be upgrading multiple packages at a time.
In my case it turned out that there was one specific package version that package-lock.json was referencing, that was 5 levels deep in the dependency. That version no longer existed at the npm registry so it caused the install to break. I had to find which package was pulling in this dependency and upgrade that one to resolve the issue.
Just delete package-lock.json file and then install package(s) you want. All will work.
Delete node_modules
Just delete package-lock.json file and then install packages you want with npm install . All will work.
rm -rf node_modules
rm package-lock.json
npm install
If the issue still persists check if you have a global version of any of the packages installed.
This can happen if you have a global version of a package that clashes with a local version of a package.
I was struggling with this for awhile, and it seems be be related to the following.
Let's say you have 3 modules, A, B and C
Module A includes B and C directly
Module B also includes module C, in it's package.json dependencies.
If your package.json dependencies in module A look like the following:
"dependencies": {
"C": "^1.0.0",
"B": "^1.1.0"
}
You will get the above error you mentioned, ENOENT, blah, blah in .staging
If on the other hand you include the module with the nested include first like:
"dependencies": {
"B": "^1.1.0",
"C": "^1.0.0"
}
The error goes away. This seems like a bug in npm with nested dependencies, and the error messages and logs were not very descriptive. Check your dependency tree and see if you have the described case, if so, that is your issue.
Beside removing package-lock.json I had to remove node_modules so package-lock.json could be generated in the right way
rm -rf node_modules
rm package-lock.json
npm i
I have presented this same error due to npm cache problems. Run
npm install --cache /tmp/empty-cache
This happened to me when I was on Node.js 12 attempting to run npm install against a package-lock.json generated using Node.js 16.
Switching back to Node.js 16 resolved the issue:
nvm use 16
Of course, deleting the package-lock.json would have also resolved the issue for me.
If you dont have package-lock.json or package.json under your working folder, call npm init first.
Checkout package-lock.json from upstream and re-run npm install
I'm dealing with this issue right now, and it seems to have something to do with the way package-lock.json gets generated.
The problem finally resolved itself when I checked out package-lock.json from my team's upstream repository and re-ran npm install.

install a node js package from tar

I have created a tar file from my entire package directory including the package file and try to use the command
npm install package.tar
from my projects folder where the tar file is, however I am getting an error that says:
ENOENT: no such file or directory, open 'C:\Projects\package.json'
If I try to put the package.json file in projects folder, I get:
Refusing to install package as a dependency of itself
C:\Projects>npm install nodeTest.tar
C:\Projects
`-- node-test#1.0.0
npm WARN enoent ENOENT: no such file or directory, open
'C:\Projects\package.json'
npm WARN Projects No description
npm WARN Projects No repository field.
npm WARN Projects No README data
npm WARN Projects No license field.
How exactly do I install a package from a tar file?
I just want to be able to install a package from a file without pulling from published online npm packages

Resources