Everytime I run npm install, I get the extraneous warning/error - node.js

Every single package I install using npm i is extraneous and is not added to package.json. With npm i --save, it will get added but I wonder why this is. I've tested in different directories to make sure the problem is not the parent folder having a node_modules folder.
I'm using node 8.10.0 and npm 3.5.2

So I updated npm using npm, I deleted the local repo and cloned it again, I created test node projects in different directories but the problem persisted.
I'm not sure what stopped it because it resolved on its own after a while, but before that, I was running npm i with --save.

Related

npx create-react-app is using wrong node_modules folder

I have node installed through nvm and I'm currently using v10.16.3. This lives in C:\Users\User\AppData\Roaming\nvm. When I try running npx create-react-app new-app, it tells me I'm using npm v3.5.3, and subsequently fails with a MODULE_NOT_FOUND involving 'internal/util/types'. I suspect this is because it's trying to use the bloody old npm version.
The frustrating thing is, when I run npm -v it tells me v6.9.0. In that nvm folder, in node_modules folder, I see an npm folder whose package json indeed tells me it's v6.9.0. However, in another part of my pc, I have a massive node_modules folder (C:\Users\User\node_modules), and this is where it's somehow trying to access npm. This is where the old v3.5.3 lives. I've checked my PATH vars, nothing is pointing here. Why the heck is nvm deciding not to use the npm that lives in its own damn folder?
I tried deleting the old npm in the wrong folder, but that clearly didn't fix anything.

npm ERR! cb() never called! error when trying to run npm install command

I have this react-native project I worked on my other pc, and I want now to keep working on this exact project folder in my other linux machine.
So now I have the project folder, which doesn't contain node_modules directory, but it does contain "package.json". As I understood it, doing NPM install inside the directory, should install and create the node_modules directory with all the needed dependencies.
However, the operation is failed after a while with the error "npm ERR! cb() never called!"
I've already tried to clean npm cache (with -f flag) but it doesn't worked for me.
I'm running on Ubuntu 18.04 based os with Node.js v8.10.0 and npm v3.5.2.
In my case, I had an own custom node_module which is in my package.json like that:
// ...
"dependencies": {
// ...
"my-module": "file:../../my-module",
},
// ...
This package is only available in a specific environment (dynamically added to package.json via npm install ../../my-module), which is by intend,
but I forgot about it and when I ran npm install in another environment (where my module was not available)
the mysteriuos cb() never called error occured.
After putting the option --no-package-lock behind the npm install the error got more clear, telling me that it has something to do with my-module.
see also: https://stackoverflow.com/a/52474959/3063191
Hope this helps :)
I my case i was able to fix it by deleting
node_modules
package-lock.json
and then running npm install
I had similar issue for git project. The Project configuration had created bad .npmrc file, which was preventing package installation. I resolved it by deleting the .npmrc file, then performing hte following steps:
Delete the node_modules folder from project, if it exists
Delete temp files from machine
Run npm cache clean --force
Run npm install
Manually delete the package-lock.json file and then run "npm install". It should re-generate the package-lock.json.
let me save your time , Just install latest Nodejs. I was trying all day. Finally this solved

Why does npm install local packages in my home directory?

Node.js newbie here, Windows 10. I npm install-ed some packages (without -g) while inside a directory that didn't have package.json. npm placed the packages in C:\Users\{MyName}\node_modules\.
Now I'm seeing some weird behavior:
When I'm in my project directory (has package.json but no node_modules/ yet), npm list and npm list -g both show an empty list
When I'm in a non-project directory (no package.json)...
npm list -g still shows an empty list
However, npm list shows everything in C:\Users\{MyName}\node_modules\
Question 1. What is going on here? Apparently, npm's default global path should be C:\Users\{MyName}\AppData\Roaming\npm\. If so, why is it using C:\Users\{MyName}\node_modules\?
Question 2. How do I get out of this mess? Node.js has no problem importing packages from C:\Users\{MyName}\node_modules\, but I want npm to list them properly. How can I delete the semi-global packages, reinstall them correctly, and ensure that this doesn't happen again?
Welp, turns out I've been mistakenly npm install-ing packages without package.json. The first time I did this, I was in my home directory(C:\Users\{MyName}\). This caused npm to create node_modules/ and package-lock.json in the home directory. Further (mistaken) attempts to install packages in my projects--which were still missing package.json--caused npm to traverse upwards, until it found the initial node_modules/ dir, and install everything there. Because my home directory is among the places Node.js looks for modules, I didn't notice my mistake until now. :P
Not sure why it’s doing it, but the way to avoid it is to initialize your project directory using:
npm init
or if you don’t want to answer the questions:
npm init -y
That will setup the directory with the package.json and node_modules will be put there.
Ok, a couple of tips then...
when you install a package that you are going to use in production then add --save, e.g.
npm install --save some-package
this will automatically add the dependency to your package.json. If you are installing a package for use purely in development, e.g. chai, then use--save-devand it will add it to the development dependencies.
Also, git is your friend, even if you are only messing :)
Happy noding :)
For me the solution here was:
Go to c:\users[me]\AppData\Roaming\npm and delete the node_modules folder completely
Make sure I had the package.json file for the project
Delete the project package-lock.json file
Run npm init
Run npm install
Project then worked, not sure why the node_modules got to be in the folder above, ain't got time to find out.

Why do Node modules go into .staging folder?

I have an Electron app that I'm trying to install node modules for. When I run npm install, it creates the node_modules folder but all the modules go into a subfolder called .staging. Each module also has -xxxxx appended to it, where the x's are some random alphanumerics.
Other Electron apps I've created have never done this. All the node modules sit in the root of node_modules and don't have -xxxxx appended.
Any idea why this is happening?
I was also facing the same issue, I tried the steps below:
Delete package-lock.json
Delete Node Modules folder
Try installing it using below command (should be in open network)
npm install
Note: - ".staging" means, those dependencies are getting downloaded so for the temporary basis it keeps all those dependencies under ".staging" folder. Once all gets downloaded properly then it will showcase them under node_modules only.
I hope this will work.
This only happens temporarily until the modules are downloaded and installed. Node seems to do this so it can place together common submodules from all the modules you are installing so it can better structure the node modules folder(mainly for windows users).
If this is happening after an npm install finishes it is likely that there is something wrong with your node installation or something in the install failed.
If you're automatically installing node_modules using CI/CD you should check out npm ci. Also check out this Stackoverflow question.
npm ci
The documentation points out the differences between npm install and npm ci.
The project must have an existing package-lock.json or npm-shrinkwrap.json
If dependencies in the package lock do not match those in package.json, npm ci will exit with an error, instead of updating the package lock.
npm ci can only install entire projects at a time: individual dependencies cannot be added with this command.
If a node_modules is already present, it will be automatically removed before npm ci begins its install. This is nice, because it prevents having to do something like rm -rf node_modules.
It will never write to package.json or any of the package-locks: installs are essentially frozen.
.staging is a temporary npm folder, where the modules are temporarily saved while they are being downloaded, if the package.json downloads are still not completed, the created folder remains, until the installation is complete.
The problem may be lack of space on your hard drive.
I was having 2 versions of node installed on my system.
nodejs v4.2 and node v8.6
I thought this could be conflicting, so I deleted nodejs v4.2 with following commands.
sudo apt-get remove nodejs
and linked the path with
sudo ln -s /usr/bin/node /usr/bin/nodejs
Again I ran npm install and it got fixed
Delete package.lock.json
Delete node_modules
run npm update
This worked for me
I moved the project from C drive to other drive and ran the following commands
take a backup of older node modules if you are running this and existing project
npm cache clean --force
npm update
I faced similar issue and tried the above answers but it did'nt worked for me;
I followed below steps to resolve this issue-
1.npm audit
By running npm audit I got list of pending packages to install-
2.npm i packagename
After installing one or two package one by one from list, I used
3.npm install
At this time the installation went smooth without any lag or hangup. Hope this help who is facing similar issue :).
Sometimes the cache is corrupt and also unremovable.
This fixed the issue I was experiencing.
If you are using nvm
Get the current node version node --version
nvm uninstall (that version)
nvm install (that version)
nvm use
npm install
If you have a windows machine where you do not posses Admin rights to it.
Try deleting node_modules and install using 'npm install' from command line as
'ADMINISTRATOR'
It works!
Anyways, it comes down to an open network thing ;)

npm list is not pointing to the node_modules folder

I have recently install nvm, node and npm. I cant seem to get the $npm list to list the modules in the node_modules folder. Other npm commands work. npm install -g installs in the correct folder which I can see by cd'ing to it. I cant figure out why one npm command works but the next doesnt. npm config shows cwd as a different folder. Do I have to change that? If so, how do i do that? Thank you.
https://gist.github.com/kaona/0d5ba467cff814dbb1691a083baa1dee
I also tried this but didnt work. I know its something simple im missing. Still new to this. Thanks.
Have you included the modules in your package.json file? The npm list command won't show a module if its not in the package.json, even if its installed in the node_modules directory.
The tree shown is the logical dependency tree, based on package dependencies, not the physical layout of your node_modules folder.
https://docs.npmjs.com/cli/ls
When you install a module into your app, use the --save or --save-dev options to update your package.json. This allows you to install all the dependencies of your application by running npm install. It will also mean that your modules show up when you use the npm list command.
https://docs.npmjs.com/cli/install - For more details

Resources