How can I clear the central cache for `npx`? - npx

Let's say you're running this command:
npx gulp
npx will search for gulp within node_modules/.bin, and if it doesn't find it there, it will use a central cache. If it is missing, npx will install it.
How do I clear the central cache to force npx to reinstall gulp in this case?

On macOS (and likely Linux) it's ~/.npm/_npx, you can drop it with:
rm -rf ~/.npm/_npx
On Windows it should be %LocalAppData%/npm-cache/_npx
Either way, you can find npm’s cache by running npm config get cache and then finding an npx folder in there.

I needed to do this, due to an error in create-react-app saying 'We no longer support global installation of Create React App.' despite there being no global install. It was stuck in the npx cache, and I removed it like this
npx clear-npx-cache

Related

Uninstall package using npx

I trying uninstall package, who I installed by:
npx terminalgpt
I trying:
npm uninstall -g terminalgpt
But is not working, how I can uninstall this package?
you don't have to
If any requested packages are not present in the local project dependencies, then they are installed to a folder in the npm cache, which is added to the PATH environment variable in the executed process.
— from npx doc
that cache folder is like a temporary folder you don't have to specially care yourself about.
If you really want to clean your cache, see npm cache doc

How to solve 'vue-cli-service' is not recognized as an internal or external command?

I am getting an error when trying to run npm run serve. At first I installed node.js then vue as well as vue/cli.
But when I am trying to run server as -> npm run serve at that time I'm getting error like 'vue-cli-service' is not recognized as an internal or external command.
I used below codes for installation:
npm install -g vue
npm install -g #vue/cli
can someone guide me what to do to solve this issue ?
I think you are using cmd in windows.
Try deleting the node_modules folder and after that run npm i from the cmd.
Then try running npm run serve again and see if it works this time
Install vue/cli-service globally
npm install #vue/cli-service -g
This will install global npm package.
#vue/cli-service is usully installed as global, because you do not usually copy these types of packages to every project.
If the global npm package gets corrupted, it is not stored in node_modules folder, but rather in other depending on the os. Therefore removing node_modules does not help. Locations for global node_modules folders are
%USERPROFILE%\AppData\Roaming\npm\node_modules (Win10) or
/usr/local/lib/node_modules (Linux),
check this stack overflow post on how to locate global packages.
it will depend on the package manager you are using
delete node_modules
if you are using yarn run yarn or yarn install and then yarn serve
if you are using npm run npm install and then npm run serve
In my case, the package #vue/cli-service is installed in my local node_modules environment, but not my global environment, so it cannot be used as a command. I type .\node_modules\.bin\vue-cli-service serve and it works.
As it is mentioned in terminal that node_modules is missing from your project, so you can't directly use npm run serve, first you have to do npm install then do npm run serve. It will work fine
In my case I ran below commands in GitBash and it worked fine
npm install
npm run serve
If you are using cmd in windows.
deleting the node_modules folder and after that run npm istall from
the cmd.
run npm run serve and see if it works this time
In my case, I have checked the folder of node_modules was missing. I am using Windows. So I run this in cmd.
npm install
npm run serve
Then I check it in localhost like usual.
This issue mostly happens when either #vue/cli is not installed or in most cases,
#vue/cli is already installed and you are currently working on a project and when running
yarn serve or npm run serve.
Most at times, this issue is been caused by broken dependencies.
to fix this issue, simple run
yarn install or npm install
depending on your package manager.
well after trying all the solutions above and it still haven't worked for you then you probably have a stupid space in the full directory of your Vue project like in my case. so remove that that space and it will work from then on.
Remember to set the NODE_ENV=development and run npm install again
Try changing the project path to one without spaces, it worked on windows 10
I had faced the same problem in windows. Then
first I deleted the node_module. then I run npm install.
For Windows you should modify package.json to:
"scripts": {
"serve": "vue-cli-service.cmd serve",
"build": "vue-cli-service.cmd build",
"lint": "vue-cli-service.cmd lint"
}
,
I had the same issue using windows + WSL2 (Ubuntu 20.04). Looking at the logs generated after trying to run npm i I noticed that my WSL2 environment did not have python2 installed. So to solve I ran the following commands:
sudo apt-get install python2
rm -rf node_modules
npm i
npm run serve
I faced the same in Windows. Had to run npm install again. Then it worked perfectly.
Wait, what's the difference between #vue/cli and #vue/cli-service? When you install both, they show different number of packages installed. The latter solved my issue actually but everyone keeps saying install #vue/cli.
try running npm i or npm install and then proceed to run npm i vue after previous installation done. works for me
you need use "npm install" at Command Line
Before running "npm install", try running this command first:
npm set strict-ssl false
Like you, I got the error below when I ran npm run serve from the CMD command line,
'vue-cli-service' is not recognized as an internal or external
command, operable program or batch file.
I got past this familiar error by using the following command to add the npm folder to the PATH that CMD searches for executables:
path=%path%;C:\Users\<USERNAME>\AppData\Roaming\npm
where <USERNAME> is your Windows user profile directory name. Only then was I able to run the following commands successfully:
npm install
npm run serve
What solved the issue for me was renaming the directory. I had used the symbol "&" on the folder name and it seems to break things, so changing it to "and" fixed the issue.
This will probably be an incredibly niche thing, but if I help even 1 person it's fine by me.
I have a project, I can run it well on Linux, but i have the same issue on windows, I solve it this way (I hope in your case it works too):
Delete the node_modules
Install it again with npm i

Cannot Find Module

I am trying to run react-native start and the following error appears
"Cannot find module 'metro-core'. Run CLI with --verbose flag for more details.
Prior to getting this message, I had a different error message saying modules was not located, so I tried this:
Delete the node_modules folder -
rm -rf node_modules && npm install
Reset packager cache - rm -fr $TMPDIR/react-* or node_modules/react-native/packager/packager.sh --reset-cache
Clear watchman watches - watchman watch-del-all
I just typed in the react-native start and the error message popped up on the simulator, which told me to look at my terminal for the error message.
This is common with NPM. Do not worry. Just follow a few steps and you will get your package.
Step 1: $ npm cache clean --force
Step 2: delete node_modules by $ rm -rf node_modules folder or delete it manually by going into the directory and right-click > delete.
Step 3: npm install
To start again, $ npm start
This worked for me. Hopes it works for you too.
Still, if it is there, kindly checks the error it displays in red and acts accordingly.
Be careful when using rm -rf.
After that,
While working on Unix systems.
Sometimes it may not allow you to install such packages. For that, you need sudo permissions.
Sometimes, the package is installed but only in your local modules, and when you try to import(require) it from outside of the directory, the error occurs.
Sometimes, your compiler read your dependencies, but not able to find this package in that, at that time also you face this error.
Anyways, don't worry. You just have to follow some steps below.
A best practice is to initialize your project using npm init before starting development. This will initialize your project and generate package.json file. (Ignore it if your project have package.json file)
Then, if you want any library as dependencies, try --save with npm install command. This will save your dependency in package.json file.
e.g. npm install metro-core --save
If any package is not found after installing, install it globally by -g flag.
Globally installed packages will be accessible within your system. e.g. npm install metro-core -g.
Note: Unix system needs SUDO permission for installing it globally.
I hope this will help you.
npm install metro-core
use command then run

Command invalid: run always ask to create a project

I have a project about 4 months and suddenly the aurelia's CLI commands are not working.
When I try to execute au run --watch I receive a message with options to create a new project under the path.
I have already tried to uninstall and reinstall the aurelia CLI, It's not work.
The last thing I have done was to execute a git clean -xdf
I think that could be something on my project. Someone could help me?
ANSWER
After some attempts I fixed the problem:
1) I reinstall Git and Node;
2) I have deleted all the files under the \AppData\Roaming\npm-cache path;
3) I have checked if the Git and Node were in the PATH of environment variables;
4) I run the npm install command;
Is aurelia-cli included in the devDependencies of the project and also installed globally?
First, install globally:
npm i -g aurelia-cli
Then, in the project directory, install & save to devDependencies:
npm i --save-dev aurelia-cli
You should then be able to run au in the project directory and see that the build and run commands are now available.
Note that you'll also need to install the necessary gulp dependencies required by the tasks in your project devDependencies.
EDIT: See aurelia/cli/issues/485 which confirms that installing aurelia-cli as a local dependency fixes this issue.

'react-native' is not recognized as an internal or external command, operable program or batch file

I recently started with react-native. I install it using the tutorial on the Facebook site and everything works well for a day or two until this message comes up:
'react-native' is not recognized as an internal or external command,
operable program or batch file.
Nothing works except uninstalling everything and starting all over again. The environments are ok and work (npm, choco, etc.). I have also tried removing and adding react-native to environment variables, restarting, and running cmd in administrator mode, but nothing so far. I should add that I use windows 10 64-bit.
I had the same issue and tried the following but didnt work
Adding npm path to my Environment variables; both system and user
Re install npm and react-native-cli
Both didn't work for me, im using Windows 10;
Solution that worked for me is to install react-native-cli globally
You can install it globally by using the below command:
npm install -g react-native-cli
You can simply use npx react-native <command> it will work
npm install -g react-native-cli
But dont forget to restart command promprt
Your system or user environment PATH variable was edited, you can uninstall NodeJs and install it again or add the below path to the end of PATH variable into user variables the restart the Windows :
C:\Users\[USER-NAME]\AppData\Roaming\npm
this should work.
You need to setup the npm path in your environment variables. Please look at the images down below
Then follow the command : for installing -g ( global ) for cli in your system
npm install -g react-native-cli
I get the same error right off the bat on Windows 10 running in cmd window in adminstrator mode, however there is also a bash shell version of react-native that worked for me in a git bash window.
cmd:----------------------------------------------
C:\Users\David\Documents\react>where react-native
C:\Users\David\AppData\Roaming\npm\react-native
C:\Users\David\AppData\Roaming\npm\react-native.cmd
C:\Users\David\Documents\react>react-native init AwesomeProject
'react-native' is not recognized as an internal or external command,
operable program or batch file.
git bash:----------------------------------------
David#CYBER-PC ~/Documents/react
$ react-native init AwesomeProject
This will walk you through creating a new React Native project in c:\Users\David\Documents\react\AwesomeProject
Installing react-native package from npm...
Setting up new React Native app in c:\Users\David\Documents\react\AwesomeProject
AwesomeProject#0.0.1 c:\Users\David\Documents\react\AwesomeProject`-- react#15.3.1
To run your app on iOS:
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-ios
- or -
Open c:\Users\David\Documents\react\AwesomeProject\ios\AwesomeProject.xcodeproj in Xcode
Hit the Run button
To run your app on Android:
Have an Android emulator running (quickest way to get started), or a device connected
cd c:\Users\David\Documents\react\AwesomeProject
react-native run-android
npm install -g react-native-cli
I had to add the %APPDATA%\npm folder to my PATH on Windows 10. Global modules are installed there.
If uninstalling and installing again the npm did not work on you, try adding %APPDATA%\npm to path (Environment variables) then quick reboot/restart. System Reboot should really be part of the process. This worked on my end.
Install :
npm install -g react-native-cli
Uninstall :
npm uninstall -g react-native-cli
If you are following the getting started guide for Windows/Android, they recommend installing nodejs via Chocolatey. But Chocolatey likes to have administrator rights when it installs things. If you're just a regular user, this seems to interfere with how npm installs react-native-cli. In my case, the react-native command was only recognized when I launched a command prompt as admin.
What I did to fix:
launched command prompt as admin
uninstalled react-native-cli globally: npm uninstall -g react-native-cli
uninstalled nodejs via Chocolatey: choco uninstall nodejs
Now, as a regular user without admin rights:
installed nodejs via the nodejs website (not Chocolatey)
installed react-native-cli globally: npm install -g react-native-cli
I uninstalled node.js and then reinstalled it, and it worked like a charm
just uninstall the node.js and reinstall it..
then install the cli package typing command
npm install -g react-native-cli..
now you are ready to make your project.
To make project open a folder from your drive wherever your folder is located.
Then type command
react-native init albums
it will create a project for you inside your directory.
None of the above mentioned solutions worked for me. What did work was to remove nodejs, and reinstall it via Chocolatey with the following command:
PS > choco install -y nodejs.install python2 jdk8
> npm install -g react-native-cli
C:\Users\user\AppData\Roaming\npm\react-native ->
C:\Users\user\AppData\Roaming\npm\node_modules\react-native-cli\index.js
+ react-native-cli#2.0.1
added 41 packages from 15 contributors in 4.528s
I had this problem also becuase I restored my files from a previous OS installation. My problem was a wrong prefix in my C:\Users\user_name\.npmrc file.
Run npm config list and make sure that all your npm config variables are leading to the correct file paths. Delete the .npmrc file if you want have it to go back to the defaults. That's what I did and react-native command is working for me again.
I hope this helps.
i have no clear idea but below steps worked for me.
delete Node Modules
Uninstall react-native cli. This is Recommended in the react-native Documentation
"If you previously installed a global react-native-cli package, please remove it as it may cause unexpected issues."
npm uninstall -g react-native-cli
clean gradlew. in your project folder, go to the android folder by typing cd android
and run gradlew clean
move back to your project folder cd .., then run
npx react-native run-android
these steps worked for me. took some time when running first time.
use node.js stable version or recommended version.
On window 10, nodejs>11 global node libraries seems to be installed in C:\Users\your_user_name.npm-global. So you need to set the variable to point to that path
I had problems because of this strange mistake.
I checked to see if it was globally loaded again
I didn't delete all packages
I even deleted C:\Users[USER-NAME]\AppData\Roaming\ npm manually, but there was no solution.
The only thing that is the solution is to use the current version of node.js.
uninstall nodejs completely(restart your pc) and reinstall it using chocolatey and follow other commands from https://facebook.github.io/react-native/docs/getting-started.
worked perfectly fine for me!
Even if you have installed react-native globally and still get the same try adding path of npm module (C:\Users\your user name\AppData\Roaming\npm) to system variables instead of user variables.
I know it's too late, anyway
Make sure you've added the path of the NPM in system variable rather than user variable in the System Environment Variables.
PATH : C:\Users\user_name\AppData\Roaming\npm
Open a the command prompt and type: npm config list:
Get the path underlined in red and add it your system path (change two back slashes into one), for example: C:\Users\YOURNAME\AppData\Roaming\npm.
This solved the issue for me
I just wrote "react-native -v" to console to check have I still react-native and then just I wrote "react-native run-android" again and this time it worked. Yes just that. React native is terrible technology.
Looks like I have uninstalled react native cli by mistake, I tried all answers mentioned above, but the below command worked for me.
npx react-native run-android.
Solution
I was facing 'react-native' is not recognized as an internal or external command,operable program or batch file error when I was running react-native start in VsCode.
I Solved it by running npm install -g react-native-cli in PowerShell
Steps to follow
run PowerShell as admin (important step)
run running npm install -g react-native-cli in PowerShell
close VsCode and rerun it
that's all!
I solve this problem by running
npm install -g react-native-cli
then another error appears
Command run-android unrecognized.
I fixed this error by
npm install
Use npx before your command
npx react-native
Not just
react-native
if you faced the same issue as me just type :
npm i react-native
then try to create a new project as its recommended by the react native doc by typing :
npx react-native init yourProjectName
this should resolve your problem
hope this was helpful