When using the npm install -g yo command, an error is produced: ERR

After attempting an npm install, I encountered the following error message.

npm install -g yo
npm ERR! Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR!  { [Error: EACCES, mkdir '/usr/local/lib/node_modules/yo']
npm ERR!   errno: 3,
npm ERR!   code: 'EACCES',
npm ERR!   path: '/usr/local/lib/node_modules/yo',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/yo',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack: 
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53',
npm ERR!      'Object.oncomplete (fs.js:107:15)' ] }
npm ERR! 
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Darwin 12.5.0
npm ERR! command "node" "/usr/local/bin/npm" "install" "-g" "yo"
npm ERR! cwd /Users/hemanth
npm ERR! node -v v0.10.29
npm ERR! npm -v 1.4.14
npm ERR! path /usr/local/lib/node_modules/yo
npm ERR! fstream_path /usr/local/lib/node_modules/yo
npm ERR! fstream_type Directory
npm ERR! fstream_class DirWriter
npm ERR! code EACCES
npm ERR! errno 3
npm ERR! stack Error: EACCES, mkdir '/usr/local/lib/node_modules/yo'
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:36:23
npm ERR! fstream_stack /usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:37:53
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/hemanth/npm-debug.log
npm ERR! not ok code 0

I attempted to change the permissions of /usr/local using chown, but I am unsure if it has resolved my issue. What steps should I take to fix it?

Answer â„–1

Update

Oops, seems like I misread your operating system; you're actually on a Mac. However, feel free to try out the following steps as they might still be effective (assuming node was installed via Homebrew).


I recently dabbled with npm on Linux and here's how I managed to resolve it...

To start, adjust the global npm prefix for a local user installation:

mkdir ~/.node && npm config set prefix ~/.node

Note that npm versions up to 1.4.20 can be glitchy (due to ignoring prefix configuration), so initially, we'll install the latest npm for your user's environment.

npm install -g --prefix=~/.node npm

Finally, update your environment variables in a file like ~/.bashrc or any preferred location...

if [ -d "$HOME/.node/bin" ]; then
    PATH="$HOME/.node/bin:$PATH"
fi

export NODE_PATH="$NODE_PATH:$HOME/.node/lib/node_modules"

Ensure to source it afterward and you should be good to proceed

source ~/.bashrc

Answer â„–2

For an explanation on why the command below should be effective, refer to this hyperlink

sudo npm install -g yo

Answer â„–3

experiment using

run this in your terminal:
sudo mkdir -p /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules
npm install -g yo

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Troubleshooting: Issue with Dependency Injection functionality in Angular 2 starter project

I’ve encountered a strange error whenever I attempt to inject any dependency TypeError: Cannot set property 'stack' of undefined at NoProviderError.set [as stack] (errors.js:64) at assignAll (zone.js:704) at NoProviderError.ZoneAwareError (zon ...

"Make sure to specify Safari input field as an email and mark

I am experiencing an issue with a contact form in my HTML/PHP code. Everything seems to be working fine, but when using the SAFARI browser, the form fails to validate if I try to submit without filling out all input fields. For example, my form includes: ...

Searching for an object in Vue 3 Composition API and displaying its contents

Experiencing a challenge with my first Vue.js project, seeking assistance in resolving the issue. Upon receiving a response from my API, I retrieve a list of projects and aim to locate the one matching the ID provided in the URL parameter. A peculiar error ...

Assorted Three.js particles

As a beginner in the world of three.js, I'm currently tackling the challenge of incorporating 1000 particles, each unique in size and color. The current roadblock I'm facing is that all particles end up the same color and size when using a Partic ...

Generating npm package without including file extensions in imports

I am currently working on creating an internal library for my workplace. Everything seems to be going smoothly until I try to use it in another project. It appears that the file extension in all of the import statements has disappeared during the npm pack ...

Connect Angular to a dynamic table of information

Currently delving into Angular and facing an issue where I need to utilize an mvc handler that returns a generic JsonObject. This means the object could be of various types and have different numbers of columns. Rather than statically defining columns in t ...

Emulating a button press on the login screen

I have been attempting to utilize jQuery to simulate a button click on a login page. Interestingly, the conventional JavaScript method functions as expected: document.getElementById('loginButton').click(); However, the same action using jQuery ...

React application experiencing asynchronous function that is not returning

In my React app, I have an asynchronous function in a file (someFile.js) and I need the returned string from that function (someFunction) to be displayed on the webpage once it's done. However, I'm facing an issue where the webpage appears blank ...

Sending data from an AngularJS app to Google App Engine using HTTP post

I'm facing a small issue where I am unable to successfully POST my data (comments) to the GAE datastore using angularjs. Can you please help me identify what's wrong with the following angularjs "post" or html code? ANGULAR: $scope.addComment = ...

Lambda script for Amazon Alexa Skill is not functioning as expected

I am currently developing a Lambda function for an Amazon Alexa skill using NodeJS. For those unfamiliar, Alexa is a cylindrical speaker that responds to voice commands, and a "skill" is essentially a voice-operated app for the device. This particular func ...

What is the significance of the --only=dev flag in a package.json file?

"cd client && npm install --only=dev && npm install && npm run build" Explain the purpose of --only=dev in package.json files. Discuss the potential impact on the code if --only=dev is not included. ...

Can someone help clear up this confusion with CSS?

Why is image 6.png selected, when all the images are direct descendants of the div shape? Thank you for your assistance, it's greatly appreciated. As far as I know, it should select all the divs because they are all direct descendants of the div #shap ...

Showing particular classes on an element using intersectionObserver/Scrollspy: a step-by-step guide

Here are three different sections on my Vue page. <section id="home">Home</section> <section id="about">About</section> <section id="contact">Contact</section> When I click on a Navbar Link ...

"Transmitting a message with socket.io upon establishing connection

Currently getting the hang of socket.io and giving it a try. I have a straightforward app where clicking the display button shows an image on the screen in real time. I have a couple of questions. Firstly, my main concern is regarding the synchronization ...

Tips for deactivating trackball rotation events and triggering a custom rotation event while adjusting the rotation speed within the custom event

In an attempt to disable the trackball control rotate event and trigger a custom rotate event, I have encountered some challenges. While setting controls.enableRotate = false; works for OrbitControl, it does not completely disable the trackball control r ...

Retrieve external URL from backend and perform a redirection after clicking on the <p:button> element

I have a task that I am working on where I need to display a button. The target URL for this button is obtained by making a SOAP request to an external third party (Single Sign In) which provides the sign-in URL. I want to ensure that my page's load t ...

Gulp is throwing an error stating that it is unable to locate the module 'babel/register'

Currently, I am in the process of updating a project to a new node version. The update went smoothly, but now gulp is not functioning properly. Every time I try to run gulp, I encounter Error message when running gulp Error: Cannot find module 'babel ...

Trouble with loading document on 'load' event listener

Primary Concern Currently, my script operates smoothly when it listens for a click event on the element with the id share. I am looking to switch this functionality to activate on the $(document).on(load) event while removing the share button. However, up ...

Experiment with using webdriverio and javascript to select checkboxes

Currently, I am experimenting with testing the selection of checkboxes using webdriverio in combination with mocha and chai. Below is an example of what I attempted utilizing a javascript module pattern select_checkbox: function(browser, key, value){ r ...

The jQuery.addClass() function seems to be malfunctioning

I'm encountering an issue with the addClass() method. For some reason, it's not functioning properly in this scenario: https://jsfiddle.net/0g1Lvk2j/20/ If you scroll to the end and close the last box by clicking on the orange box, the orange b ...