Unable to install angular cli with npm errno -4048 package.json - node.js

I tried installing angular cli with npm. But I'm getting the below error while executing the command npm install -g #angular/cli.
I am not executing this command as admin, but as a user.
D:\AngularWorkstation>npm install -g #angular/cli
npm WARN sass-loader#6.0.6 requires a peer of node-sass#^4.0.0 but none is installed. You must install peer dependencies yourself.
npm ERR! path **D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall rename
npm ERR! Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' -> 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! cause:
npm ERR! { Error: EPERM: operation not permitted, rename 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json.365294863' ->** 'D:\node_modules\node_modules\#angular\cli\node_modules\which\package.json'
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'rename',
npm ERR! path: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR! dest: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json' },
npm ERR! stack: 'Error: EPERM: operation not permitted, rename \'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863\' -> \'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json\'',
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'rename',
npm ERR! path: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json.365294863',
npm ERR! dest: 'D:\\node_modules\\node_modules\\#angular\\cli\\node_modules\\which\\package.json',
npm ERR! parent: '#angular/cli' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\techno\AppData\Roaming\npm-cache\_logs\2018-01-03T09_14_35_602Z-debug.log
*PS : I'm using Windows10 OS. I also tried changing the npm global path to'D:\node_modules' to check if it's due to permission issue. However the output is the same.
node --version : v7.7.2
npm --version : 4.1.2*

I had a similar issue when trying to install Yeoman with npm on Windows 10. The culprit turned out to be the McAfee AV software that was installed on my machine.
McAfee seemed to be scanning the changes that npm was trying to make to a json file and as part of the scanning routine, prevented the rename from occurring. This resulted in a 4048 error being raised by npm similar to the error in your output.
To get around this I:
Uninstalled McAfee and restarted my machine so that it reverted to Microsoft's built-in security software.
Re-ran the npm install command and it worked correctly.
Alternatively, you could change the settings of your AV software to not actively check file changes for the node_modules folder. This would hopefully allow your AV software to stay installed and the npm command to work too.

From your error logs, It seems that there is some permission issue while installing the packages. You can specifically resolve this issue by two ways.
1) If you are trying to install the packages globally then you have to run the npm install <pkg_name> -g command with the administrative user or using sudo npm install <pkg_name> -g command.
To install the npm-packages globally you can follow the steps below:
Run the command prompt as the administrative user.
Run npm install <pkg_name> -g.
2) You should try going to the top-level folder in Windows Explorer, right-click on "get more info" option then go down to the permissions section, give yourself all permissions, and tell it to apply them recursively.
Or simply you can go to specified npm working directory and edit to permission section and allow all the permission to the current user and also change the owner to itself for all the recursive directories as well.
Then boot up Windows again.
Note: If you are installing an npm-package locally, then you should be in your local project directory and can try running sudo npm install <pkg-name> command to install required package. the purpose of using sudo is that it will change your owner permissions so you can make your current user authorized to run npm commands.
I'd recommend you to take a look at https://docs.npmjs.com/getting-started/fixing-npm-permissions

1) uninstall node
2) download latest version of node from [https://nodejs.org/en/][1] .
3) install node js

Related

I am not able to install create react app on my m1 macbook pro

Please help me with this error
I ran the following command on iterm after installing node.js and adding it into the path
npm install -g create-react-app
I get the following error
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/create-react-app'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/amaterasu/.npm/_logs/2022-01-04T08_36_06_018Z-debug.log ```
I ran into this earlier today and here is how I fixed it.
npm uninstall -g create-react-app
npx clear-npx-cache
npx create-react-app my-app
If you are interested on the details regarding this issue, than have a look at this github thread
For the npm packages you want to install globally, mainly you may encounter permission problems. This can usually be solved by adding sudo at the first of the line. So instead of:
create-react-app yourAppName
You can do this:
sudo npx create-react-app yourAppName
Following your root user password.
Also, to add more, there are some reported problems with the node js version and create react app. you can check the version of node installed in your Mac, by this command at your terminal:
node --version
if the installed version of the Node is 17.X, it can be assumed it is related to the problem.
It is always recommended to use the LTS version.
enter link description here
you need to have node version >=14 and npm >=5.6 use the command npx create-react-app myapp.
https://reactjs.org/docs/create-a-new-react-app.html#create-react-app
create one folder for react projects.
open that folder in terminal.(commandline)
And use npx create-react-app yourAppName.
Above error is permission related you dont have permission to create new folder under "/usr/local/lib/node_modules/create-react-app".
If this error still comes use sudo npx create-react-app yourAppName.

Install ReactJS on Ubuntu 18.04 -- npm permission denied

I am new to Linux and I am trying to get set-up with nodejs, but I have not been able to figure out why I can't install react. I am following directions that I have seen on the web, but I am wondering why I seem to not have the privileges necessary to install react. It's a personal environment, so I wasn't expecting any issue. Below is what I have run and the final error that the last line gave me.
sudo apt update && sudo apt upgrade
sudo apt install nodejs
sudo npm install npm
node -v
v8.10.0
npm -v
3.5.2
sudo npm install npm#latest -g
npm -v
6.10.0
npm install -g create-react-app
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/me/.npm/_logs/2019-07-06T19_33_32_971Z-debug.log
Using npx (with npm 5.2+)
If you're using npm 5.2+, you may create a ReactJS app like below:
npx create-react-app my-app
Now your app is in a folder my-app, you can cd into the folder and run npm start.
Using older versions of npm with npm install
You may also install it with a global install with npm, infact for older npm versions (< 5.2) the official documentation for create-react-app links to instructions by Dan Abramov (#co-author of create-react-app):
npm install -g create-react-app
However you may need sudo for a global -g install or work around it
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
That's because your last command is a global install (-g).
Unless there is a reason against, you may install it with sudo:
sudo npm install -g create-react-app
To install without sudo, please refer to this question: npm throws error without sudo
I was also having this issue, here is how it was resolved
Make sure you have npm installed or use:
sudo apt install npm
Then
sudo npm -g install create-react-app
To create the app I did not use 'npm' before the command line, instead use this:
create-react-app nameofyourapp
That worked for me.

npm install failed with Error: EPERM: operation not permitted, unlink '\node_modules'

I try to run "npm install" command in CMD ["node_modules" is inside C drive] but installation failing with below error.
OS :Windows 10.
Node JS version: 6.9.0.
Error: EPERM: operation not permitted, unlink.
Goal: To run AngularJs project.
CMD command
npm install -- no optional;
PS C:\Users\arunk\Work\Workspaces\workspace-2\brainbox-frontend-angular> npm install --no-optional
npm ERR! path C:\Users\arunk\Work\Workspaces\workspace-2\brainbox-frontend-angular\node_modules\.staging\typescript-5afdc8eb\lib\tsc.js
npm ERR! code EPERM
npm ERR! errno -4048
npm ERR! syscall unlink
npm ERR! Error: EPERM: operation not permitted, unlink 'C:\Users\arunk\Work\Workspaces\workspace-2\brainbox-frontend-angular\node_modules\.staging\typescript-5afdc8eb\lib\tsc.js'
npm ERR! [Error: EPERM: operation not permitted, unlink 'C:\Users\arunk\Work\Workspaces\workspace-2\brainbox-frontend-angular\node_modules\.staging\typescript-5afdc8eb\lib\tsc.js']
{
npm ERR! stack: 'Error: EPERM: operation not permitted, unlink ' +
npm ERR! "'C:\\Users\\arunk\\Work\\Workspaces\\workspace-2\\brainbox-frontend-angular\\node_modules\\.staging\\typescript-5afdc8eb\\lib\\tsc.js'",
npm ERR! errno: -4048,
npm ERR! code: 'EPERM',
npm ERR! syscall: 'unlink',
npm ERR! path: 'C:\\Users\\arunk\\Work\\Workspaces\\workspace-2\\brainbox-frontend-angular\\node_modules\\.staging\\typescript-5afdc8eb\\lib\\tsc.js'
npm ERR! }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It's possible that the file was already in use (by a text editor or antivirus),
npm ERR! or that you lack permissions to access it.
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\arunk\AppData\Roaming\npm-cache\_logs\2019-05-22T19_01_22_659Z-debug.log
I had the same problem and tried a lot of different things. This solved my problem:
1 - Uninstall NodeJs
2 - Delete folders 'npm' and 'npm-cache' from AppData/Roaming
3 - Deactivate firewall and all antivirus (including Windows Defender)
4 - Reboot the system
5 - Open command prompt as administrator and execute 'npm install'
Like you I have wasted much time trying to get 'npm install' to install Angular projects from its 'project.json' file and received similar error messages that are unhelpful; Recently I installed 'yarn' and this does a much better job of populating the 'node_modules' folder and it also generates more useful error and warning messages in the process.
Try the following steps:
Install 'Yarn' - go to it's website and download the installer for your operating system.
Got to your project directory (the one containing 'project.json')
enter the command 'yarn' and wait. This will perform the same function
as 'npm install', however it will generate fewer messages but the ones
it does will be more pertinent.
I hope this helps.
I was using yarn to install axios and got the same error, but I figured out that this error is not peculiar to axios since the same thing happens with all other packages.
Killing all running node process worked for me.
Perhaps a problem with the file system.
Check your C drive with the windows verification tool (right click on the C: -> Properties -> Tools -> Check). Repair the errors if it's needed.
It worked for me. I write here this solution for people (like me) with similar issue.
Similar problem can also happen if you try to uninstall a dependency while in another terminal window you're using
ng serve
Simply stop that operation and only then you can uninstall it.
Please try following steps:
check your antivirus status is enable or disable
disable your antivirus during the installation.
I hope this helps. It worked for me.

What should be done to have permits to join two modules of a project without using sudo?

I am trying to link two modules created by me, in a project created with Node.js, and as always I did: npm link . inside the module that I want to call, and from the other call it in package.json, and it gives me the following error:
npm ERR! path /home/miguel/cursos/cursoJs-Node/proyectoMichaelgram/michaelgram-db
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall symlink
npm ERR! Error: EACCES: permission denied, symlink '/home/miguel/cursos/cursoJs-Node/proyectoMichaelgram/michaelgram-db' -> '/usr/lib/node_modules/michaelgram-db'
npm ERR! { Error: EACCES: permission denied, symlink '/home/miguel/cursos/cursoJs-Node/proyectoMichaelgram/michaelgram-db' -> '/usr/lib/node_modules/michaelgram-db'
npm ERR! stack: 'Error: EACCES: permission denied, symlink \'/home/miguel/cursos/cursoJs-Node/proyectoMichaelgram/michaelgram-db\' -> \'/usr/lib/node_modules/michaelgram-db\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'symlink',
npm ERR! path: '/home/miguel/cursos/cursoJs-Node/proyectoMichaelgram/michaelgram-db',
npm ERR! dest: '/usr/lib/node_modules/michaelgram-db' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /home/miguel/.npm/_logs/2018-07-17T12_02_46_081Z-debug.log
How should I install Node globally?
I have seen those files and they are owned by root. I put a new version of Ubuntu 18.04 I installed node Could it be problem when installing node? I do not remember how I did it, but on previous occasions I did not have this permission problem. I do not know if I should uninstall node and npm I have to install it in a way that I can access from any project I do. I already gave another file problems and I corregi using sudo, but it does not seem like a practice, because it should not give problems, never gave them node. What do you advise me to do to correct the problem and access node_modules without using sudo? Maybe I should uninstall and install it in another way? Thank you, I hope you understand my need, forgive the syntax but I must use the translator. Thank you.
I would advice you the 2 definitive ways given in the npm documenation
1)Reinstall npm with a version manager (recommended)
2)Change npm's default directory manually.
please visit https://docs.npmjs.com/getting-started/fixing-npm-permissions

NPM won't install pug?

Can anyone help me decipher what this message is about?
I have another app with pug installed, yet now I cannot create a new module installation for some reason.
I'm installing pug local to the app into node_modules
I'm just trying to get work done, so if I have missed something simple, my stress level has not been helpful with keeping precise vision.
My system is for ongoing development so I don't muck around with upgrades, which historically has broken all kinds of other stuff.
My other app works fine.
# npm install --save pug#2.0.0-beta4 <= Because the working app uses this one
npm ERR! Linux 3.2.0-35-generic-pae
npm ERR! argv "/home/kingram/.nvm/v0.10.46/bin/node" "/home/kingram/.nvm/v0.10.46/bin/npm" "install" "--save" "pug#2.0.0-beta4"
npm ERR! node v0.10.46
npm ERR! npm v2.15.1
npm ERR! path /home/kingram/.npm/wordwrap/0.0.2
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! Error: EACCES, mkdir '/home/kingram/.npm/wordwrap/0.0.2'
npm ERR! { [Error: EACCES, mkdir '/home/kingram/.npm/wordwrap/0.0.2']
npm ERR! errno: 3,
npm ERR! code: 'EACCES',
npm ERR! path: '/home/kingram/.npm/wordwrap/0.0.2',
npm ERR! parent: 'cliui' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /home/kingram/node/fssreg/npm-debug.log
You may need to install using sudo, ie - sudo npm install .... This will prompt you for your root password.
It looks like root privileges are required to install the package you're looking for. Though this shouldn't really be the case, you can fix this....check out this link
After some prodding by #zillaofthegods, it turns out some of directories in ~/.npm were owned by root. In particular the wordwrap module directory.
Changed the permissions and npm installed it fine.
One of those things I would not have caught without some prodding, so thanks.

Resources