Warning: The usage of `--global` and `--local` in the global configuration is no longer supported. Please utilize `--location=global` instead. Additionally, an error has occurred due to an

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm ERR! Unexpected token '.'

Everything was working fine on my computer until npm/npx suddenly started throwing this error.

The same error pops up every time I run an npm command.

System configuration:

  • Operating System: Windows 10

  • Node Version: v16.15.1

  • npm Version: 8.11.0

I have attempted the following solutions:

  1. npm cache clean --force (still getting the error)
  2. Ran commands with --location=global
  3. Edited npm and npm.cmd files by replacing prefix -g with prefix --location=global

Answer №1

This is the solution

  1. Find the node.js installation folder on your computer, for example C:\Program Files\nodejs
  2. Open the file npm.cmd with administrator privileges using Notepad
  3. Replace prefix -g with prefix --location=global, and then save the changes
  4. Repeat the same process for the file npx.cmd

Check to see if the issue has been resolved

If the problem persists, attempt to update npm by running npm install npm@latest -g

https://i.stack.imgur.com/dP81c.png


Answer №2

A problem has been identified with NPM, and the best solution is to update it to either an earlier version or the latest one (the issue has also been reported in version 8.3.1). Additionally, if you are using NVM for Windows with a version below 1.1.9, you may encounter this issue with any Node version, so updating your NVM version is recommended.

Answer №3

After two days of frustration, I finally resolved the problem by installing version 16.14.2 of NodeJS instead of the latest one. Hopefully, this solution will be helpful to others facing similar issues.

Answer №4

After removing the most recent version of Nodejs, I proceeded to install Nodejs version 16.14.2 using this link

This action successfully resolved the issue I was facing

Answer №5

I just wanted to share that my problem was fixed by upgrading to node v18.4.0 and npm v8.12.1.

Answer №6

Make sure to update to the most recent nvm version 1.1.9 by visiting https://github.com/coreybutler/nvm-windows/releases

If you are using npm 16.16.0, you may receive a

npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
warning, but the npm ERR! Unexpected token '.' should not affect your npm installation or operation. However, npm version 18.6.0 will work smoothly without any issues.

Answer №7

To fix the issue, open your terminal or command prompt and type:

sudo chown -R $(whoami) $(npm config get prefix)/{lib/node_modules,bin,share}

If prompted, enter your sudo password and then proceed by running:

npm install -g nodemon

This solution worked for me and should resolve your problem as well:

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

Tips for creating $http calls in AngularJS

Having some issues with my code, as I'm unsure of the correct placement for making an $http request to a local server. api.js var express = require('express'); var router = express.Router(); var mongoose = require('mongoose'); va ...

Encountering an error while trying to run NPM install

I have attempted to uninstall and reinstall angular cli by using the following commands: sudo npm uninstall -g @angular/cli sudo npm install -g @angular/cli However, every time I run npm install, I encounter the following error: npm ERR! Unexpected toke ...

How about I visit the campgrounds/edit page for a change?

In this get route, the previous link it was redirected from is stored in the req.session object under returnTo. Once redirected, it goes to the /login and we are able to view the object in the console. router.get('/login', (req, res) => { ...

next-auth consistently redirects when encountering errors with credential providers

I've been working on integrating next-auth with my next js app using the Credentials provider. However, I'm facing an issue where every time a login fails, it automatically redirects to the /api/auth/error route. What I actually want is to handle ...

The error message "In the waterfall nodejs, the function callback is not defined"

Recently, I attempted to implement the waterfall method in my Mongoose code. However, I encountered an error that is proving difficult to resolve. Can someone provide assistance? TypeError: callback is not a function Here is my code: exports.waterfall ...

Navigating through relationships in BreezeMongo: Tips and tricks

In my current setup, I have defined two entities: Hospital and Patient with a one-to-many relationship. The metadata for these entities is created as follows: function addHospital() { addType({ name: 'Hospital', ...

The process of implementing server-side rendering for React Next applications with Material-ui using CSS

I have developed a basic React application using Next.js with an integrated express server: app.prepare() .then(() => { const server = express() server.get('/job/:id', (req, res) => { const actualPage = '/job' const ...

What is the reason for the return of undefined with getElementsByClassName() in puppeteer?

Currently, I am utilizing puppeteer to fetch certain elements from a webpage, specifically class items (divs). Although I understand that getElementsByClassName returns a list that needs to be looped through, the function always returns undefined for me, e ...

What is the best way to run an npm script with grunt-run?

I currently have a npm task specified in my package.json file for running jest tests: "scripts": { "test-jest": "jest", "jest-coverage": "jest --coverage" }, "jest": { "testEnvironment": "jsdom" }, I would like to run this task using ...

emailProtected pre-publish: Running `python build.py && webpack` command

i am currently using scratch-blocks through the Linux terminal I have encountered a problem which involves running the following command: python build.py && webpack [email protected] prepublish: python build.py && webpack Can anyon ...

Using Buffer.from() with a value less than 16 will result in the creation of an empty buffer

Take a look at this code snippet: let num01 = Buffer.from(Number(1).toString(16), "hex"); console.log(num01); let num02 = Buffer.from("02", "hex"); console.log(num02); let num16 = Buffer.from(Number(16).toString(16), "h ...

Insufficient memory causing electron-builder to encounter issues

The main issue at hand is that while trying to build and run an Electron application containing a webpack React app, we're facing challenges related to running out of heap memory. This problem has cropped up recently without any apparent correlation t ...

Struggling to establish connection with Node Server on EC2 Instance

I have set up a Node application on an AWS EC2 instance, but I'm facing issues after running npm start. Even though everything seems to be running smoothly, I can't seem to connect to the application via the web. Looking at my server.js file, it ...

The process of combining multiple JS files into one with Gulp 4 has encountered an issue: an error has occurred stating

I am currently utilizing Nodejs version 12.9.0 along with gulp version 4.0.2 My objective is to concatenate and minify multiple JS files from various source directories and bundle them into a single JS file. After concatenation and minification, I encount ...

Ways to bypass mongoose schema validation while making an update request in the API

In my model, one of the fields is specified as providerID: { type: Number, required: true, unique: true }. The providerID is a unique number that is assigned when inserting provider details for the first time. There are situations where I need to update ...

Sending form data from a React application to a backend Express server

I have a React form that captures candidate information and sends it to an Express server. I am using axios to make a POST request to the backend, where I want to log the candidate object. The form is functioning correctly in accepting input. import React, ...

Is there a way to verify user credentials on the server using FeathersJS?

Currently, my single-page app is utilizing feathers client auth and a local strategy for authentication. I have implemented various middleware routes and I am looking to verify if the user is authenticated. If not, I would like to redirect them to /. Bel ...

ADF CI Build Failure: Execution unsuccessful: node /home/shaadmin/myagent/_work/5/s/adf/build/downloads/main.js validate

Yesterday, our ADF CI Build was running smoothly based on the configuration outlined in the [Microsoft documentation][1]. However, today we encountered a sudden failure with the following error message: Command failed: node /home/shaadmin/myagent/_work/ ...

The ejs file is failing to load the css file

I'm facing an issue where my layout.ejs file is not loading the style.css file. I've been searching endlessly for a solution, trying various fixes and meticulously checking for typos. Despite the correct path shown in the network tab when inspect ...

Denying the request to include sqlite3 as a requirement for its own installation

I managed to successfully compile the latest version of node.js without any hiccups. Now, my next task is to integrate a sqlite module for node.js into my project. Following the instructions provided by developmentseed for node-sqlite3, here's what I ...