npx requires re-installation of packages every time - node.js

Currently using npx as a workaround for packages installed globally by npm as commands can never be found despite all attempts at exporting to the correct path.
npx works in finding the command but has to reinstall the package every time to find it which means multiple uses of the same package runs into problems.
I've tried using the npx --no-install but then npx runs into the same problem as I did with "command not found" being the result.
All this is attempted through the ubuntu terminal.

Solved my issue. The npx workaround was never going to work when my npm pathing was acting up. Had to reinstall npm (again) and manually create a global directory rather than use the default. Then had to export that path variable and append it to .bashrc confirm it with "source /.bashrc" and then restart the terminal. On restart everything worked fine and had no further problems with npm installs.

Related

ANY ng command will fail when trying angular due to invalid character error in ng file

The \AppData\Roaming\npm\node_modules#angular\cli\bin\ng.js file cannot be opened and it gives an error whenever I try to use an ng command anywhere, be it in an angular project or elsewhere.
The error is as follows:
Script: (my username)\AppData\Roaming\npm\node_modules#angular\cli\bin\ng.js
Line: 1
Character: 1
Error: Invalid Character
Code: 800A03F6
Source: Compilationerror Microsoft Jscript
What I have tried:
using ng commands in different project -- same error
reinstall npm, angular, removing the node modules in all combinations
Setting the angular path in the environment variables
What happened before:
ng command was missing possibly due to stuff related to python install. This error is replaced with my current problem when reinstall is done.
I have reinstalled everything to the fullest extent but the problem keeps persisting.
I can use my angular project by running 'npm run ng serve' and that weirdly works.
Does anyone have ANY idea what might cause this problem
EDIT:
I have somehow managed to resolve the problem but I have no clear answer what was the cause of it all. I did reinstall nodeJS on my computer which MIGHT have been broken during another project.
Remove the user environment variable
C:\Users\AppData\Roaming\npm\node_modules#angular\cli\bin
It worked for me after losing a day of life looking for a solution
In my case this error occured because of permissions on windows. Try to run cmd as Administrator.
Deleting and reinstalling node.js did not fix it. The issues started when I installed latest CLI which is 13.
I removed npm folder from C:\Users\username\AppData\Roaming then I installed the previous version
npm install -g #angular/cli#12.0.0
I do not get the error anymore.
What worked for me is setting this path:
set path=%PATH%;C:\Users{username}\AppData\Roaming\npm
Firstly you need to set the path of npm
$ npm config get prefix
make sure path matches with npm config get prefix
export PATH=/usr/local/share/npm/bin:$PATH
in windows you can set by advance system settings -> Environment variable -> set path.
Restart you system then do this -
$ npm install -g #angular/cli#latest
get package version
$ ng version
create workspace
$ ng new my-project
run the application
$ cd my-project
$ ng serve

npm and other modules commands not working

Note: I am on Windows 10 64 bit running the latest LTS Node build.
It all started when I tried running the command npm i -g create-react-app and I get a message saying that npm is not a command.
I checked my PATH and I believe I have the proper directories in there.
I navigated to the directory of npm and tried running the command again, but it still didn't work. I found that the command npm.cmd worked in any directory. So tried running npm.cmd i -g create-react-app and that worked! I also had to use the the command create-react-app.cmd my-app, instead of create-react-app my-app. I thought I was set and I could just use those .cmd commands for the things I needed to do; however, when I tried to run the command create-react-app.cmd my-app and got this as a result:
I have looked in the file that is ran when using this command create-react-app.cmd my-app and there is no sign of npm being called. Turns out Node is being called in that file with the command below. I know this because when I run it by itself and I get the same output to the console seen in the previous image.
"node" "C:\Users\Allen\AppData\Roaming\npm\\node_modules\create-react-app\index.js" my-app
it was called in the create-react-app.cmd file like this "%_prog%" "%dp0%\node_modules\create-react-app\index.js" %*
I am at a loss. I could continue down this rabbit hole and try and find the node file that is calling npm and change it to npm.cmd but I would rather find a way to get the npm and create-react-app commands working as they are suppose to. At the very least I can just spin up a VM and work in that. It is just annoying that I can't get Node to work properly for me.
Use the command npx create-react-app my-app this will help you create react projects.
Also check the documentation : https://reactjs.org/
First check that you have npm installed on your machine and the version. You can just type npm version. Since npm version 5.2.0 npx is pre-bundled with npm, which is a CLI tool whose purpose is to make it easy to install and manage dependencies hosted in the npm registry. So try using npx create-react-app app-name. You can confirm that you are able to use npx by running which npx. If it is not available then you can install it by running npm install -g npx.

Unable to install ionic

I'm trying to install ionic on Windows but for some reason, I'm unable to. When I run the "npm install" everything looks fine, no errors, nothing weird happens, however when I try to run "ionic start" (or any ionic command, even just ionic -version) the shell says that "ionic is not recognized as an internal or external command".
I've tried everything but obviously, I'm still doing something wrong something. I tried uninstalling/re-installing/updating everything I could so I'm pretty sure that Nodejs and npm are fine.
From what I read online I found that this kind of error happens when the environmental variables are messed up, however, I don't exactly know what I'm supposed to change there. I've followed many guides and tutorials: some of them said that the PATH to npm should be under 'Roaming', others said that the PATH should be under 'Local', some said that it should be in 'Program Files' and others said that what matters is the order in which you write the PATH variables.
Some just said to reinstall node and after that everything should be fine but none of these suggestions worked.
Can anyone help me? What kind of environmental variables do I need to put in for this to work?
Should I remove the node and start from scratch? If so, where should I install node so that I don't have weird path problems later on?
If you need any additional information on the problem please say so. Thank you in advance for your time
It looks like your npm packages are not being installed on the default npm folder (%appdata%\npm). There's this command that shows you the root global npm folder, you can run npm root -g to check where npm is installing the packages and add that path to your PATH environment variable.
First, run the command bellow:
C:\> npm root -g
It will give you a path like this:
C:\my\actual\path\node_modules
Grab the path without node_modules (C:\my\actual\path\), and then add it to your PATH environment variable.
Warning: don't forget to remove the node_modules from the path it gave you.
Once you set your PATH variable, you need to restart your computer.

bash: create-react-app: command not found (pretty sure it's my $PATH)

Let me preface by stating that this is my first post, and also I can’t retrace my steps to where the create-react-app command no longer works in my Terminal. Last week, when I was practicing how to work with ReactJS I was able to use the command create-react-app and had been able to initialize a React project. However, I’ve been fiddling plentifully with NodeJS and NPM stuff simultaneously, and now when I call the create react-app command this is the output:
bash: create-react-app: command not found
I’m pretty sure it has to do with my $PATH, however I’m not experienced with making edits through vim
when editing my .bash_profile. In my attempts to diagnose and fix the problem, here is what I appended to my $PATH through vim:
export PATH="/usr/local/bin:$PATH"
Nevertheless, I know the order of $PATH matters, but I’m naive as to whether I should prepend or append the $PATH above?
Here is what is output when I echo $PATH:
/usr/local/heroku/bin:/usr/local/bin:/usr/local/sbin:~/bin:/Users/bjornjohnramos/.rbenv/bin:/Users/bjornjohnramos/.rbenv/shims:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/bjornjohnramos/.npm-packages/bin/express
-> /Users/bjornjohnramos/.npm-packages/lib/node_modules/express-generator/bin/express-cli.js:/Users/bjornjohnramos/.npm-packages/lib:export
PATH="/usr/local/bin:$PATH":export
PATH=$PATH:/Users/my_name/.npm-packages/bin/
my node and npm versions:
node v6.9.1
npm 4.2.0
Who knows what happened? But maybe we can just fix it by reinstalling...
npm uninstall create-react-app
npm uninstall create-react-app -g
npm install create-react-app -g
The first two commands will uninstall create-react-app locally and globally. (Not sure how you may have installed it. Harmless to run both.) The third installs globally, and should set up the path for you as needed.
use command npx create-react-app my-app rather than using npx create-react-app my-app that will resolves your bash: create-react-app: command not found err on windows.
Hope this is helpful
Happy coding...

Not able to run 'npm install' on vagrant homestead

I'm trying to install Gulp & Elixir on my Laravel project but I keep getting errors when I run 'npm install'. I've also tried 'sudo npm install' but no luck there.
My Node version is: 1.4.14
It switches between these two:
For this error there was a solution posted here: https://harvsworld.com/2015/how-to-fix-npm-install-errors-on-vagrant-on-windows-because-the-paths-are-too-long/
But this has not solved the issue seeing it still happens after following the steps.
I also sometimes get these errors (the list goes on...):
Anyone know a solution? I haven't found anything yet after a couple hours of searching..
After a long search I eventually found the solution.
Seeing I'm using Homestead / Vagrant, I was using PuTTY. This was my first mistake.
Just simply use Git Bash, just make sure you run it as an administrator &
change the directory to your Laravel project.
The second thing you need to do is make sure you don't have a 'node_modules' file in your project. Just remove the files by doing:
rm -rf node_modules/
Followed by:
npm install
Everything should work now. It's a dumb mistake but hopefully through this post, people will not make the same one as I did and waste alot of time doing it..
Cheers!
You should first install node in your local machine.
Then, navigate to your project folder and run (again on your local machine!):
npm install gulp --save-dev

Resources