Lerna giving EPERM errors - node.js

when trying to run this specific command:
lerna run -parallel lint
I consistently get this error:
EPERM: operation not permitted, scandir 'C:/Users/USER1/Application Data'
This is for a simple react app and npm install, start, etc all work as intended. It is only this command that does not work.
I have already tried many different solutions including:
npm clean cache -force
Run as administrator
Change permissions for both npm, project folder, AppData/Roaming to allow anyone to have full control
Delete all node modules and reinstall using "npm install -force", "npm cache verify", or "npm install --no-bin-links"
Disable anti-virus or Windows defender
Make sure no other node servers or scripts are running
Run on PowerShell, command prompt, VSCode, etc (tried pretty much every single CLI)
Install latest version of npm
Probably some others that I have since forgotten due to trying so many solutions
Also if the problem is actually related to npm and not lerna, then unfortunately I also cannot swap to using Yarn, as this is apart of a school project where a pre-commit script runs the lerna command and I cannot change it.
Please if anyone has encountered this issue, let me know.

Related

npm and other modules commands not working

Note: I am on Windows 10 64 bit running the latest LTS Node build.
It all started when I tried running the command npm i -g create-react-app and I get a message saying that npm is not a command.
I checked my PATH and I believe I have the proper directories in there.
I navigated to the directory of npm and tried running the command again, but it still didn't work. I found that the command npm.cmd worked in any directory. So tried running npm.cmd i -g create-react-app and that worked! I also had to use the the command create-react-app.cmd my-app, instead of create-react-app my-app. I thought I was set and I could just use those .cmd commands for the things I needed to do; however, when I tried to run the command create-react-app.cmd my-app and got this as a result:
I have looked in the file that is ran when using this command create-react-app.cmd my-app and there is no sign of npm being called. Turns out Node is being called in that file with the command below. I know this because when I run it by itself and I get the same output to the console seen in the previous image.
"node" "C:\Users\Allen\AppData\Roaming\npm\\node_modules\create-react-app\index.js" my-app
it was called in the create-react-app.cmd file like this "%_prog%" "%dp0%\node_modules\create-react-app\index.js" %*
I am at a loss. I could continue down this rabbit hole and try and find the node file that is calling npm and change it to npm.cmd but I would rather find a way to get the npm and create-react-app commands working as they are suppose to. At the very least I can just spin up a VM and work in that. It is just annoying that I can't get Node to work properly for me.
Use the command npx create-react-app my-app this will help you create react projects.
Also check the documentation : https://reactjs.org/
First check that you have npm installed on your machine and the version. You can just type npm version. Since npm version 5.2.0 npx is pre-bundled with npm, which is a CLI tool whose purpose is to make it easy to install and manage dependencies hosted in the npm registry. So try using npx create-react-app app-name. You can confirm that you are able to use npx by running which npx. If it is not available then you can install it by running npm install -g npx.

node-gyp 5 on Windows: Cannot find npm\node_modules\node-gyp\bin\node-gyp.js

Running npm 6.11.3, node-gyp 5.0.3, VS2019 on Windows 10 v1903, getting this error:
Cannot find module %AppData%\npm\node_modules\node-gyp\bin\node-gyp.js (where %AppData% is expanded to the actual user-specific path).
The error only happens if the build is invoked via npm, i.e.:
npm run build
The package.json file scripts section:
"scripts": {
...
"build": "node-gyp build",
}
If node-gyp build is invoked manually outside npm context, the error is gone.
How do I get rid of the error and still use npm scripts for making builds?
Figured it out.
After upgrading to node-gyp 5 on a Windows 10 build system, I started getting the infamous Error: Cannot find module ... npm\node_modules\node-gyp\bin\node-gyp.js, caused by node_modules\npm-lifecycle\node-gyp-bin being pushed on top of my PATH by npm, exactly as described here.
None of the existing remedies I've found and tried could solve this issue for me, including installing the latest windows-build-tools. Here's exactly what I tried, in the following order:
manually clean up the mess and duplicates in System PATH and User PATH environment vars
reboot
choco unistall nodejs
rd /s %AppData%\npm\
rd /s %AppData%\npm\
choco install nodejs
npm install -g npm#latest
npm install -g node-gyp#latest
npm install -g typescript#latest
I was still getting the missing node-gyp.js error. What did help was to properly set npm config set node_gyp to point to the correct node-gyp.js, as suggested here. Yet somehow the script from that thread didn't work properly for me (as well some other PowerShell/Batch scripts I tried).
Eventually, I've come up with the following PowerShell 6 one-liner that did the trick for me:
pwsh -Command npm config set node_gyp "`u{22}$(Join-Path $(npm root -g) -ChildPath 'node-gyp\bin\node-gyp.js')`u{22}"
Hope this helps others and future-me. I'd still recommend going through the above bullet list for clean troubleshooting.

Build Failing on NPM Install - Typings

I suddenly have an issue where our build server is now failing on a web build. Our first step after getting sources is to run a PowerShell script that does a few things, including running npm install (so we do not keep all the packages in source control).
The process gets to what should be the last item in the list, and then throws
error EISDIR: illegal operation on a directory, open 'K:\_work\4\s\Web\typings'
No changes have been made to any of the package config files. I have tried several different versions of Node.js, but still get this error. I have also tried installing the typings version we are using (1.3.1) globally on the server, and that does not work either.
The code being run by PowerShell:
Write-Host "START: running npm install"
[string] $pkg_dir = #(Join-Path $Env:BUILD_SOURCESDIRECTORY "\Web")
&npm --prefix $pkg_dir install $pkg_dir --loglevel "error"
Write-Host "FINISHED: running npm install"
Given this, I have no idea how it would even try to do anything with the offending directory, or where I would put any directory checking code (as mentioned in the comments).

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.

Setting the global NPM folder

So ultimately, I am trying to install gulp by following this tutorial http://travismaynard.com/writing/getting-started-with-gulp, and I was having a lot of problems initially. I kept getting the error that "gulp is not recognized as an internal or external command", which is confusing to me because I found that by running npm ls that gulp had been installed properly. The command wasn't being recognized even after restarting command prompt. I found an article online http://blog.webbb.be/command-not-found-node-npm/ that I may have installed gulp in my local folder other than the global node_module folder. However, when I tried to reset the npm folder with npm config set prefix usr/local/, I received errors. If anyone can walk me through getting the global NPM folder set up and getting the gulp command to work properly, that would be much appreciated.
Try running command prompt as administrator,
or sudo since you seem to be on unix,
you install a package globally by using npm -g,

Resources