[BUG] npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\userName\AppData\Roaming\npm'
Problem
Is there an existing issue for this? - [X] I have searched the existing issues This issue exists in the latest npm version - [x] I am using the latest npm Current Behavior When "npm install" runs on pipeline server, sometimes below error occurs: npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\userName\AppData\Roaming\npm' Expected Behavior npm install succeeds with no error Steps To Reproduce 1. Newly installing node 18.17.1 with npm version: 9.6.7 which replaces node 16.17.1 and npm 8.15.0 2. Run 'npm install' 3. See error npm ERR! enoent ENOENT: no such file or directory, lstat 'C:\Users\userName\AppData\Roaming\npm' Workaround may be to create a C:\Users\userName\AppData\Roaming\npm folder manually. Environment - npm:9.6.7 - Node.js:18.17.1 - OS Name:Windows - npm config: [code block]
Error Output
error ### Steps To Reproduce
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Fix npm ENOENT Error by Creating Missing Directory
The error occurs because the npm installation process expects a directory at 'C:\Users\userName\AppData\Roaming\npm' to exist for storing global packages. If this directory is missing, npm cannot function properly, leading to the ENOENT error during 'npm install'. This can happen if the npm installation process did not create the directory due to permission issues or if the directory was deleted accidentally.
Awaiting Verification
Be the first to verify this fix
- 1
Check for Existing npm Directory
Verify if the directory 'C:\Users\userName\AppData\Roaming\npm' exists.
bashif not exist "C:\Users\userName\AppData\Roaming\npm" mkdir "C:\Users\userName\AppData\Roaming\npm" - 2
Create Missing npm Directory
If the directory does not exist, create it manually using the command prompt or PowerShell.
bashmkdir "C:\Users\userName\AppData\Roaming\npm" - 3
Set npm Prefix Configuration
Configure npm to use the created directory as the prefix for global installations.
bashnpm config set prefix "C:\Users\userName\AppData\Roaming\npm" - 4
Run npm install Again
Attempt to run 'npm install' again to verify if the issue is resolved.
bashnpm install - 5
Check npm Configuration
Verify that npm is configured correctly by checking the prefix setting.
bashnpm config get prefix
Validation
Confirm that 'npm install' completes successfully without errors. Additionally, check that the directory 'C:\Users\userName\AppData\Roaming\npm' exists and contains the necessary files after installation.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep