How to run npm scripts with WinPTY? - windows

I had the known issue of python freezing in Git bash on windows. Many answers on stackoverflow suggested to use WinPTY.
Which works fine when I use:
winpty python foo.py
But I run a python program as part of a npm script. My package.json has this:
"scripts": {
"start": "python foo.py && something else"
}
So I figure I will need to run npm script with WinPTY too:
winpty npm start
But this is not working. I got different error messages on different environments.
I got "Not found in PATH" at work which has latest git and npm installed, but it is in PATH:
winpty: error: cannot start 'npm': Not found in PATH
I got a different error at my personal computer with a slightly older git:
Error 0x2 starting npm start
Any ideas why npm and winpty isn't working together?
If I run npm start without winpty it works fine. winpty node works too.

I got the same problem.
Actually, in nodejs installation folder, there is npm.cmd
So what you should do to start npm using winpty is
winpty npm.cmd install

Related

Npm can be found but using "npm run something" gives the "npm is not recognized" error

I'm using git bash that was installed with the git for windows bundle, and this is what I have:
where node
C:\Program Files\nodejs\node.exe
where npm
C:\Program Files\nodejs\npm
C:\Program Files\nodejs\npm.cmd
But running any npm run * related script tells me that npm can't be found. Not sure what is wrong with the setup, as the paths seem right and "where" can find them. I can execute npm and node from this git bash (for example I can run node -v and npm -v) but I can't run any script.
I tried reinstalling both node and git bash but it didn't have any effect.
Any idea what could be wrong?

nodemon : command not found

On Mac, Homebrew to install node
Installed nodemon with the following command : npm i -g nodemon
But whenever I tried using nodemon it told me : command not found
I then tried adding to the $PATH in my ~/.zprofile (I'm using zsh) the following : /Users/me/npm/lib/node_modules
which I got from using the command npm root -g
Got the following error : zsh: permission denied: nodemon
All the other "solutions" involves using SUDO to install a package, which I would like to avoid.
Fixed by making sure the folder npm was mine with sudo chown -R ``whoami`` npm
The correct way was to add /npm/binand not /npm/lib/node_modulesto the $PATH

"exp: command not found" How do I add expo cli to path?

I installed the expo cli with
npm i -g exp
then I run
exp
and I get
-bash: exp: command not found
I'm guessing I didn't add exp to path. So how do I do this properly? Nothing I've tried so far works.
This suggested 3 steps solution worked for me:
First check if ~/.npm-global/bin is in your path: echo $PATH. If it isn’t there, you will need to add it to the path.
Open up ~/.bash_profile then add the following line to the bottom: export PATH=$PATH:~/.npm-global/bin
Finally, back in the shell, type: source ~/.bash_profile
Hopefully that will have fixed your problem.
1. Find the path where expo is globally installed by npm:
npm bin -g
2. Add path from Step 1 to paths file:
sudo vi /etc/paths
3. Restart the Terminal
You should try npx expo init <your_app_name> to test.
It worked for me.
I also had a hard time getting expo command to work on Mac. Here are the steps I took to get it working.
npm root -g shows the directory the global modules are installed in:
/usr/local/Cellar/node/11.7.0/lib/node_modules
That directory might be different for you. After confirming expo is in there, edit ~/.bash_profile and add the line:
export PATH=$PATH:/usr/local/Cellar/node/11.7.0/bin
Save & exit, then run source ~/.bash_profile
Now the expo command should function as intended.
try sudo npm install --global expo-cli
this worked for me.
➜ MobileDev git:(campaigns-responsive) ✗ expo whoami
› Not logged in, run expo login to authenticate
➜ MobileDev git:(campaigns-responsive) ✗ expo init App
✔ Choose a template: › blank a minimal app as clean as an empty canvas
✔ Downloaded and extracted project files.
📦 Using npm to install packages.
✔ Installed JavaScript dependencies.
✅ Your project is ready!
To run your project, navigate to the directory and run one of the following npm commands.
- cd App
- npm start # you can open iOS, Android, or web from here, or run them directly with the commands below.
- npm run android
- npm run ios
- npm run web
exp was replaced with expo
To install Expo CLI, just run npm install -g expo-cli (or yarn global add expo-cli, whichever you prefer).
Following on this issue, I found I had multiple global folders so I started using a .npm-global folder as shown here: https://docs.npmjs.com/getting-started/fixing-npm-permissions
And now it's all clean and in control.
I had a similar issue.
-bash: expo: command not found
It turns out the command to install expo
npm install -g expo-cli was referencing an older version of node on my machine; when checked using npm root -g.
So I had to uninstall nvm/node, deleted any remnant folders & files of .nvm and shortcuts for nvm in /usr/local. Then reinstalled node and ran npm install -g expo-cli again.
That fixed my issue.
sudo npm install --unsafe-perm -g expo-cli
If you're using git bash on windows, add npm path to your system path variables. Generally located on this location:
C:\Users\<Username>\AppData\Roaming\npm
Then open the bash and command npm start. Hope this will help.
I solved it by putting this in my PATH environment variable / user variable:
C:\Users\{userName}\node_modules\.bin
yarn expo start
Worked for me.
npx create-expo-app project-name

Trying to run 'npm install --save-dev paraviewweb' on my machine, and I keep running into an error at canvas#1.6.11 install

There seems to be an issue with my windows build tools ( I already re-installed and updated it ) and I installed the gyp packages too. However Im currently stuck getting this error after trying to run the above command. What is the issue and how can I fix it?
npm config set msvs_version 2015 --global
npm install -g node-sass
running these commands in the directory solves this issue.
https://github.com/nodejs/node-gyp/issues/119#issuecomment-318609877
credit to this person.

Npm Please try using this command again as root/administrator

I've been desperately trying to install modules using node.js but it always fails getting packages with npm.
I logged in as Administrator and used powershell/cmd with "run as administrator". I also had problems with the registry so I used npm set registry http://registry.npmjs.org/
I tried everything... it just drives me nuts.
Here are the errors:
npm ERR! Please try running this command again as root/Administrator.
npm ERR! System Windows_NT 6.2.9200
npm ERR! command "C:\\Program Files\\nodejs\\\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "generator-knockout"
npm ERR! cwd D:\Sergiu\Knockout Test
npm ERR! node -v v0.10.26
npm ERR! npm -v 1.4.3
npm ERR! path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js
npm ERR! fstream_path D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js
npm ERR! fstream_type File
npm ERR! fstream_class FileWriter
npm ERR! code EPERM
npm ERR! errno 50
npm ERR! stack Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\block-stream\block-stream.js'
npm ERR! fstream_stack C:\Program Files\nodejs\node_modules\npm\node_modules\fstream\lib\writer.js:284:26
npm ERR! fstream_stack Object.oncomplete (fs.js:107:15)
npm ERR! Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE'
npm ERR! { [Error: EPERM, lstat 'D:\Sergiu\Knockout Test\node_modules\generator-knockout\node_modules\yeoman-generator\node_modules\tar\node_modules\fstream\LICENSE']
npm ERR! errno: 50,
npm ERR! code: 'EPERM',
npm ERR! path: 'D:\\Sergiu\\Knockout Test\\node_modules\\generator-knockout\\node_modules\\yeoman-generator\\node_modules\\tar\\node_modules\\fstream\\LICENSE',
npm ERR! fstream_type: 'File',
npm ERR! fstream_path: 'D:\\Sergiu\\Knockout Test\\node_modules\\generator-knockout\\node_modules\\yeoman-generator\\node_modules\\tar\\node_modules\\fstream\\LICENSE',
npm ERR! fstream_class: 'FileWriter',
npm ERR! fstream_stack:
npm ERR! [ 'C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\fstream\\lib\\writer.js:284:26',
npm ERR! 'Object.oncomplete (fs.js:107:15)' ] }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
It turns out that you don’t have to run the command again as Administrator, and doing so won’t fix the problem.
Try:
npm cache clean first.
If that doesn’t fix things, take a look in %APPDATA%\npm-cache, or if you’re using PowerShell, $env:APPDATA\npm-cache.
After cleaning the cache, you may still be left with remnants. Manually remove everything in that directory, and try again. This has always fixed things for me.
As #Crazzymatt was mentioning, as of the npm#5 version and up, we need to use npm cache verify instead of npm cache clean. Or else you will get an error as preceding.
npm ERR! As of npm#5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
(Source: MSDN Blog post)
I solve it running as administrator cmd.
Cleaning the cache
npm cache clean -f
And then try to install the package again
You should run cmd.exe as administrator.
Follow the following steps:
Click Start, click All Programs, and then click Accessories.
Right-click Command prompt, and then click Run as administrator.
Here is how I fixed this on my Windows (7) Dev. environment.
I assume the following...
You are Running Command Prompt, Git Bash, Cmder or your favorite Terminal, as an Administrator by right clicking
Privileges Permissions have been granted for Read/Write (i.e chmod -777)
Okay, let's get to it:
Update any packages where a version check is returning a warning ("npm WARN"..) for example...
npm update -g npm
npm update -g graceful-fs
Next we want to force a cache clean. This is flagged by an '--f' or '-f'..
npm cache clean --f
In Widows Explorer search for the following path
%APPDATA%\npm-cache
And Delete it's contents
Start a fresh instance of your Terminal, remembering to 'Right-Click' and 'Run as Administrator', install the packages again.
Hope this helps someone!!
I was already running the Node Command Window as Administrator. As mentioned by many above, the following command with --f (force) solved my issue.
npm cache clean -f
After the Cache Clean, the install was flawless. See the screenshot for reference
I had to login into npm to resolve this issue.
npm login
If you're using TFS or any other source control for your project that sets your checked in files to readonly mode, then you gotta make sure package.json is checked out before running npm install. I've made this mistake plenty of times.
I had the same problem and I've fixed the error by cleaning the cache:
npm cache clean -f
I had the same problem, what I did to solve it was ran the cmd.exe as administrator even though my account was already set as an administrator.
Try following steps
1. Run this command on Terminal or CMD - npm cache clean
2. Go to this folder on windows %APPDATA%\npm-cache And delete folder which you want to install module (Ex:- laravel-elixir) or if you are using PowerShell, $env:APPDATA\npm-cache
3. Then Run your command EX:- npm install laravel-elixir
Here is how I fixed the problem in Windows. I was trying to install the CLI for Angular.
Turn off firewall and antivirus protections.
Right click the nodejs folder (under Program Files), select Properties (scroll all the way down), click the Security tab, and click all items in the ALLOW column (for All System Packages and any user or group that allows you to add the “allow” checkmark).
Click the Windows icon. Type cmd. Right click the top result and select Run as Administrator. A command window results.
Type npm cache clean. If there is an error, close log files or anything open and rerun.
Type npm install -g #angular/cli (Or whatever npm install command you are using)
Check the installation by typing ng –version (Or whatever you need to verify your install)
Good luck!
Note: If you are still having problems, check the Path in Environmental Variables. (To access: Control Panel → System and Security → System → Advanced system settings → Environment variables.) My path variable included the following:
C:\Users\Michele\AppData\Roaming\npm
npm cache verify
Try for newer versions of npm.
I'm using v 5.5.1 and it's working fine.
This is the flow often happens in this case. You run a command with no admin rights, you get message npm ERR! Please try running this command again as root/Administrator.. Then you open one more CLI(cmd, powershell, bash or whatever) and don't close the previous CLI. It appears you have 2 prompts opened in the same directory. And until you close CLI which runs with no admin rights you will be continuously getting npm ERR! Please try running this command again as root/Administrator. So close CLI which runs with no admins rights before running a new one.
NOTE: a lot of IDE has embedded CLI(Visual Studio, VS Code etc) so please close the instance of IDE as well
For those doing this on a MAC. Simply put sudo in front of the command. It will ask you for your password and then run fine. Cheers
What helped me on Windows 10 was just ticking off "Read Only" of project node_modules.
I messed with this problem 2 times and tried all suggestions here with mediocre success.
First time I tried (and succeeded luckily) by:
delete the node_modules folder in your project
npm clean cache -f
check your %APPDATA%/npm-cache and delete everything if not empty
start the terminal as administrator (in my opinion, it isnt a problem of rights, but it wont hurt if you do so)
npm install and then npm update
you will get errors, just install every module that throws an error manually and step by step try to eliminate everything whats wrong
However, this method is quite frustrating and not working everytime. So try this:
Second time I had no luck with the steps above, so I tried to completely reinstall npm and it failed. So I thought there must something be wrong with my node.js installation. My team is running 6.10. and I had the 6.11. and tried it with the 6.10. with no luck.
So I completely wiped everything off my system. Deleted all node modules, checked every path where node or npm could be and cleaned my system.
Then I installed newest 8.1.3
Deleted my project and cloned it to a complete different directory.
Now I installed and updated everything with npm install npm update
Then I compiled with just 2 modules missing and installed them manually
Tadaaaaa, its working now. So all in all it was a problem with node.js. I recommend to everyone who runs into this problem: Try different node versions! And clean ABSOLUTE everything.
As my last resort with this error I created a fresh windows 10 virtual machine and installed the latest nodejs (v6). But there was a host of other "ERRs!" to work through.
I had to run npm cache clean --force which ironically will give you a message that reads "I sure hope you know what you are doing". That seems to have worked.
It doesn't solve the issue on my main Dev machine. I'm canning nodejs as I found over the last few years that you spend more time on fixing it rather than on actual development. I had fewer issues with node on linux ubuntu 14.04 if that's any help.
Deleting the global npm-cache and/or running my cmd line as admin did not work for me. Also, as of npm version 5.x.x, it supposedly recovers from cache corruption by itself.
This did work:
1. Deleted the node_modules folder in my current project.
2. Deleted the package-lock.json in my current project
3. Installed the new package. In my case: npm install bootstrap#next --save
4. Ran npm install for my current project.
Everything now works. In general, nuking node_modules and package-lock.json usually fix these "no apparent reason" bugs for me.
EDIT
I just had the same problem again. But I noticed that everything was installed correctly even though it threw the error after I had followed the steps outlined above. So I could just run ng serve (for Angular), and everything worked.
This sure is a weird error...
As a hack,
Check if the folder path it is complaining exists or not.
If not, try creating them manually and rerun the installation, after clearing the cache
I had success with this, when running the installation from command prompt as an Administrator didn't work
$ npm cache clean
npm ERR! As of npm#5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use 'npm cache verify' instead.
I tried running npm cache verify with admin rights and it worked after that.
This worked for me, if your package.json is not too big you can do this:
Signout then signin.
Delete node_modules.
npm install again.
Like the other answers, clean npm cache and make sure the cache folder is empty, then run npm install several times. Each time the error message comes for different packages, and the final time (after X attempts) it succeeds.
Run npm clean cache --force
cd %APPDATA%\npm-cache (or cd $env:APPDATA\npm-cache for PowerShell)
del * to delete everything in the folder
Go back into the project folder and run npm install several times until it succeeds. Notice that the error messages come for different packages every time.
WHAT WORKED FOR ME
I ran Command Prompt as Administrator. This helped partially - as I no longer got the error, "Please try using this command again as root/administrator". I was trying to install Cordova. To do it successfully, I also had to do the following:
(1) "npm update node", plus...
(2) I also added the " -g " in the >>npm install cordova<<. In other words, type this: >>npm install -g cordova<<
~~~ FOR WINDOWS 8.1 ~~~
"RUN AS ADMINISTRATOR" COMMAND PROMPT
For windows 8.1, I don't have an ACCESSORIES group when I click START > ALL PROGRAMS. But I do have that older -- but trusty and reliable -- START BUTTON and START MENU - thanks to the free Classic Start Menu app. So, with that installed....
ALTERNATIVE #1:
1. Type "cmd" in the SEARCH BOX at the bottom of the START menu.
2. When cmd.exe shows up in the top of the search results, right click it and select RUN AS ADMINISTRATOR.
ALTERNATIVE #2 If you already have a Command Prompt window open and running - and you want to open another one to Run As Administrator:
1. Locate the Command Prompt app icon in the Taskbar (usually along the bottom of you screen unless you have moved it a different dock/location).
2. Right click the app icon.
3. Now, right click "COMMAND PROMPT" and select RUN AS ADMINISTRATOR.
Hope this helps someone.
I don't know which steps worked for me. But these are my steps to get rid of this error:
Updated Node.js
Ran npm cache clean command in Command prompt ( With
some element of doubt for cache presence)
Ran react-native init in
command prompt as Administrator (on Windows OS), hoping works well
with sudo react-native init on Mac OS
Close the IDE
Close the node terminals running ng serve or npm start
Go to your project folder/node_modules and see you if can find the package that you are trying to install
If you find the package you are searching then delete package folder
In case, this is your 1st npm install then skip step 4 and delete everything inside the node_modules. If you don't find node_modules then create one folder in your project.
Open the terminal in admin mode and do npm install.
That should fix the issue hopefully
FINALLY Got this working after 4 hours of installing, uninstalling, updating, blah blah.
The only thing that did it was to use an older version of node v8.9.1 x64
This was a PC windows 10.
Hope this helps someone.
If you're in react native project, and Expo is running, then close it.
Re-install the package, and everything should be fine.
Also remember to end all other npm commands e.g. npm run dev-server.
A solution that worked, is to close all PowerShell and cmd instances. Start PowerShell/cmd again as administrator and things seem to work.
This can happen if you're doing react-native and the node.js cmd is open in the background.
On windows 10,
npm cache clean --force and npm cache verify did not work for me.
Tried to delete cache folder and file with administrator permission, did not work.
The process-explorer tool helped me finding that Node.exe is holding on the cache file. I killed the process and tried to clean, worked.

Resources