how to un-init NPM? - node.js

So oddly I really cannot find the answer to this question and after a few posts and docs I've looked at on NPM I've decided to ask the question - which may be a very basic one but doesn't seem to be implicitly addressed...
How do you uninstall npm from a dir?
Premis:
you npm init -y on the wrong directory
desired outcome:
to remove npm from that directory
I'm working on windows 10 / using git bash on VS code terminal
any help here would be appreciated -
Wally

All npm init does is setting up package.json for you (guided or not). If you just del package.json from the wrong directory, you should be good to go.

Deleting the package.json from the wrong directory should do the trick.
You will have to keep in mind that if in case you have run the npm i or npm install commands after npm init you will also have to delete the node_modules folder (as it usually takes plenty of disk space) and run npm i now in the correct directory.

Related

Issue cloning every repository

I have been cloning repositories with node and MongoDB but I always run into issues running npm install when I cd into the folder directory.
It has to be me because I happens every time. What am I missing?
Seems like npm install is the 3rd step after 1: git clone "repository link", 2: cd in clone folder.
Please guide me in the right direction.
Thanks a ton
You can run npm install from a directory where package.json file is located since this is the one which holds all the info regarding packages.
So just try to make it sure that the directory from where you are firing npm install command, have package.json file.
Apart from this, just check if you have npm installed. Run npm -v

How do I get spectacle-code-slide working on Windows?

I have installed Node on a Windows 10 machine. Then did npm install spectacle from the node command prompt. Finally downloaded the spectacle-code-slide zip file. Moved into the folder, did npm install and npm start. I get the following:
npm ERR: missing script: start.
Obviously, I am missing something. What is it? Note: I am a complete noob!
Edit: I tried the process outlined here without success.
This error means that you don't have start script in your package.json. Read about scripts here.
When you run npm instal spectacle you install spectacle as a package into node_modules folder. So you don't have any scripts in your package.json except those you add there yourself.
I've actually never used spectacle, but I suppose you better use their spectacle-boilerplate (instead of doing npm instal spectacle). You need to clone (via git) or download that repository locally. And then you will have their package.json with start script in it.

npm ERR! Error: EPERM: operation not permitted, rename

When I execute npm install I get this error
npm ERR! Error: EPERM: operation not permitted, rename C:\projects******\node_modules\react-async-script' -> 'C:\projects*******\node_modules.react-async-script.DELETE'
I am running the cmd as administrator
I ran npm cache clean before
I made sure all the other applications don't have anything related to node_modules open
In my situation this helped:
Before proceeding to execute these commands close all VS Code instances.
clean cache with
npm cache clean --force
install the latest version of npm globally as admin:
npm install -g npm#latest --force
clean cache with
npm cache clean --force
Try to install your component once again.
I hope this fix your issue. If not, you may temporarily disable your antivirus program and try again.
For me i just closed the Code editor (VS Code) and then run the same command. And that solves the issue for me.
I got it working when tried npm install with a force option to fetch remote resources even if a local copy exists on disk. Try running
npm install --force
Updated
For some of my colleagues this solution was not working. But we tried using yarn instead of npm. It works (faster as well) without any issues all the time
yarn install [package-name]
Not package.json, but for whatever reason, my node_modules/ had become read-only. Resetting that fixed this.
If you want to avoid the --force option (which is always a better approach), I suggest making sure that you have stopped running the project, as this is usually the main reason for locking the files in almost 90% of the cases I have seen
I suggest the following steps in this order:
1- In Angular stopping ng s and in React stopping npm start usually solves this issue because usually this error happens if a development server is running the project as it locks some files & then npm can't update them thus throwing this error
2- If the above doesn't work, then try closing the code editor that has the workspace opened in it (maybe it was locking some files or something)
So try closing the code editor & running:
npm install
3- If still it doesn't work, then maybe you can try the --force option
npm install --force
I was getting that same error and according to https://github.com/Medium/phantomjs/issues/19 it could be caused by your antivirus software. I disabled mine for the duration of the install and executed "npm install" on cmd as admin and it worked.
Hope this helps.
I was getting the same thing. I didn't find this anywhere but it hit me that our VMs tend to change files to a read-only state. So I opened package.json's file properties and deselected Read-only in the "General" tab.
Steps
Go to the package.json file.
Right-click and select Properties.
In the General tab, Attributes section, deselect Read-only.
Click Apply to apply the change.
This is a typical error caused by Antivirus. There is a workaround for cases like mine, where I can't disable A/V (Company Policy).
You have to change the polyfills.js inside Npm package:
[NODE_HOME]/node_modules/npm/node_modules/graceful_fs/polyfills.js
Look for this statement:
if (process.platform === "win32") {
Inside of this statement, there is a timeout making a retry in case of error. The problem is that in some cases, after the timeout, the file is still locked by the A/V. The solution is rip out the timeout and let this statement in loop. The change with the previous code commented:
if (platform === "win32") {
fs.rename = (function (fs$rename) { return function (from, to, cb) {
var start = Date.now()
var backoff = 0;
fs$rename(from, to, function CB (er) {
if (er
&& (er.code === "EACCES" || er.code === "EPERM")
/*&& Date.now() - start < 60000*/) {
console.log("Retrying rename file: " + from + " <> " + to)
fs$rename(from, to, CB);
/*setTimeout(function() {
fs.stat(to, function (stater, st) {
if (stater && stater.code === "ENOENT")
fs$rename(from, to, CB);
else
cb(er)
})
}, backoff)*/
if (backoff < 100)
backoff += 10;
return;
}
if (cb) cb(er)
})
}})(fs.rename)
}
As Martin Kearn pointed out in a comment, closing Visual Studio resolved these npm permission issues for me. Evidently VS sometimes locks files in node_modules.
I have had this issue multiple times only in Windows
I try these in the order usually.
npm install --force
Check if node_modules is set to read-only and
remove if it is
Delete node_modules/
Check if any editor is opened
that could have access to the root folder of the project
Reboot :(
Usually trying npm install after one of those steps will resolve it.
Trying to rename a file to another filename that already exists can cause an EPERM error on Windows.
In my case, something got locked up and a quick reboot resolved it.
Closing PHPStorm fixed the issue for me.
just close the VS Code to solve the issue for me
I am using macOS catalina ,
npm init
I got error
operation not permitted, uv_cwd
in 2021, this is how you can fix this problem.
very simple:
step 1: go to parent folder
cd ../
step 2: go to your project folder again,
cd your-project-folder
That is it. It works.
I did the following:
Upgraded the npm to the latest version: npm install -g
npm#6.5.0-next.0
deleted the npm-cache folder from: c:/users/[username]/AppData/Roaming/npm-cache
Did cache clean : npm cache clean --force
Ran the npm install.
I struggeled with this too.
I finaly a solution that works fine if you use nvm:
cd ~/.nvm/versions/node/{your node version}/lib/
npm install npm
and that's it.
I'm using the terminal in VSCode and I realized I was using the bash terminal instead of the node terminal.
npm was failing for me at scandir for:
npm install -g webpack
...which might be caused by npm attempting to "modify" files that were potentially locked by other processes as mentioned here and in few other github threads. After force cleaning the cache, verifying cache, running as admin, disabling the AV, etc the solution that actually worked for me was closing any thing that might be placing a lock the files (i.e. restarting my computer).
I hope this helps someone struggling.
I had the same problem. The reason for the error is unsupported characters in the path to the file. Replaced the cyrillic in English - it helped.
For some, AppRoot\npm folder could be an issue. Sometimes the AppRoot folder is marked as network shared and thus Antivirus blocks the stuff. Follow below link for complete solution.
https://alastaircrabtree.com/fixing-intermittant-eperm-operation-not-permitted-on-npm-install/
I hope this helps.
Open the command prompt as administrator and navigate to the project location and then run npm install. it worked for me.
I remounted my window disks with the metadata flag, and instantly helped: https://devblogs.microsoft.com/commandline/chmod-chown-wsl-improvements/
after that no need anymore to use sudo for npm commands as the metadata keeps windows and linux file/directory permissions in check.
In my case running npm: v6.9.0 && node: v10.16.1 on Windows, I had to run my CLI (git bash) as administrator. Then packages were installed without any warnings/errors
I had the same problem after updating to npm to 5.4.2, npm start giving the same error for most npm commands. Some solution suggest to run it with --no-optional, but it didn't always work.
Others suggested to downgrade, but I didn't want to downgrade.
I suspected that there was a problem with the installation, not sure what it was.
So I re-updated my npm:
npm i -g npm
and worked fine since then.
run the CLI as administrator always solve the problem for me
I came here with the same error, followed all the answers here, and none solved it. I started going through my package.json removing all suspicious packages. Removing this unnecessary one solved our problem. "npm": "^8.3.2"
I think it should be related to updating npm issue. As a workaround for now you can specify npm version as 8.3.1.
- name: Install latest npm version
run: npm install --global npm#8.3.1
I'm updating Angular 13 to 14 and I faced this issue.
None of these solutions worked so I just restarted the laptop and the npm i --force worked!
It seems like one process on the background is locking the access to certain node_modules files (you may have an ng serve running somewhere, or been launched by a git bash which you close but kept running on the background)
My answer is to do npm cache clean --force first. Then run npm install -g npm#5.3.0 to install npm 5.3.0 version. for me, this npm version works with no trouble.

npm install resulting in 'ENOENT: no such file or directory'

I've installed Node.js for Windows and I'm trying to install a package via npm. The command prompt is in the directory of the project (C:\Users\username\Desktop\NodeTest), which contains a single helloworld.js file. Upon typing 'npm install express', I receive the following error:
ENOENT: no such file or direcotry, open 'C:\Users\username\package.json
I'm attempting this from a clean install and cmd is running as admin.
Any ideas?
I was facing the same issue. I firstly delete my node_modules and delete the cache by following command:
rm -rf node_modules && npm cache clean --force
then I delete the package-lock.json file from my project and then hit npm install in command prompt and it works.
As already pointed out by Subburaj this is because you are missing a package.json.
Just run npm init to initialize that file for you; afterwards it should work.
If you are working on a Windows machine using Vagrant/VM, there's a chance that symlinks are the culprit for your problem. To determine if that is the case, simply copy your package.json and package-lock.json into a test directory that is not mounted/shared between OSs.
mkdir /tmp/symlinktest
cd {{your directory with your package*.json}}
cp package*.json /tmp/symlinktest
cd /tmp/symlinktest
npm install
If this results in a successful install, you'll need to either exclude the node_modules directory from the mount (there's various articles on doing this, however I can't say I've had success) or run npm install outside the mounted volume.
I deleted the package-lock.json and It worked for me.
Basically I was Offline while I tried to install with npm, so go online and try
npm install again
Check the project folder which you opened in microsoft visual code. Generally you are not in the right path so npm is not able to search the package.json ... My project was in Document/hostel/hostel .. I opened Document/hostel ... So npm tried to find the package.json in Documents folder .. When i entered one level inside to Document/hostel/hostel .. it was fixed.

Error message "ENOENT, no such file or directory"

I'm getting this error from my Node.js application:
ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'
I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.
I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below):
The fix for me was: npm init --yes
Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or use
process.env.HOME + '/Desktop/blahblahblah'
I was also plagued by this error, and after trying all the other answers, magically found the following solution:
Delete file package-lock.json and the node_modules folder, and then run npm install again.
If that doesn't work, try running these in order:
npm install
npm cache clean --force
npm install -g npm
npm install
(taken from #Thisuri's answer and #Mathias Falci's comment respectively)
And then re-deleting the above files and rerunning npm install.
It worked for me!
First try npm install. If the issue is not yet fixed, try the following one after the other.
npm cache clean, then
npm install -g npm , then
npm install. Finally
ng serve --o to run the project.
__dirname
Gives you the current Node.js application's root directory.
In your case, you'd use
__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';
See this answer:
How can I get the application base path from a module in Node.js?
I had that issue using the path module:
const path = require('path');
And also do not forget to create the uploads directory first period.
Specifically, rm yarn.lock and then yarn install fixed this for me.
For those running Laravel Mix with npm run watch, just terminate the script and run the command again.
For me, it had my code folder in Dropbox on Windows 10. During the build process Dropbox would flip out over having more than 500,000 files. I moved my folder out and now it builds fine!
When this happened to me, it was when trying to run Karma tests in an Angular project. The tsconfig.spec.js file turned out to be incorrect. It was basically pointing to the wrong directory, and so the error was simply trying to tell me this.
For example, we had ../tsconfig.json instead of ./tsconfig.json, so the runner was looking for tests in the wrong folder. This may be a different use case from the OP, but the same error message brought me here and led me down the rabbit hole of trying the npm install solutions to no avail.
It usually occurs due to a mismatch in the npm version used while creating the package-lock.json that currently exist and the one you are using now.
Removing the package-lock.json and running npm install worked for me.
Sometimes you are just not in the right directory. Check that once and try "npm start" again.
Reason: I have the same issue, where a few guys work on one project and change package dependencies.
Solution: Just kill file package-lock.json and run npm i again
In my case, I was running the terminal in the wrong folder. Please make sure that you navigate to the folder containing your code (App.js and others) and then use a command prompt (for Windows) to open the code. I am using Visual Studio Code, so it is to type "code." after I have opened the command prompt in the exact folder where my code is in.
I ran into this upgrading a Phoenix app to 1.6, which does not use Node.js, so in fact it is not needed. However, elixir_buildpack.config had a reference to phoenix_static_buildpack.config, which defined node. Remove the reference, and the error goes away.
My problem was that I didn't have a package.json file in my working directory.
Another possibility is that you are missing an .npmrc file if you are pulling any packages that are not publicly available.
You will need to add an .npmrc file at the root directory and add the private/internal registry inside of the .npmrc file like this:
registry=http://private.package.source/secret/npm-packages/

Resources