Not able to run 'npm install' on vagrant homestead - node.js

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

Related

error when running npm run build in prestashop local environment

I've been stuck for quite a while. I'm currently starting a local environment for Prestashop and when I go into the _dev folder and run npm run build or npm run watch to watch my changes. I receive the error below. I've done rm -rf node_modules and reinstalled them, I have also tried uninstalling webpack and node-sass and reinstalling but still no luck. can somebody tell me where I am going wrong or what is causing this?

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.

npx requires re-installation of packages every time

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.

Installing node modules in Openshift Python gear

I have a Python application in Openshift, with Python 3.3 and PostgreSQL cartridges. The Python cartridge is running Django 1.8, based off the template on the Website.
Recently, I started using Gulp to automate my build, and while it's worked great on my local machine, I can't figure out what to do to use it in Openshift. I have django-gulp installed so it just runs whenever I use runserver, but the Openshift server obviously doesn't have gulp or any plugins installed, so that won't do anything. I don't know how to install them on the server, though.
Including a package.json does nothing. I've tested it and it works fine if I go with a node cartridge, but I've got a Python one.
Since npm is on the server, I tried SSHing and running npm install manually, but it threw up a permission denied error.
So, after trying to work this out for a while, I've finally figured out a solution. This is a bit convoluted, but it does work:
Install your own Node and npm. The version included in Openshift is hopelessly outdated and doesn't really work. SSH into your server and install a local version in your dependencies folder. cd $OPENSHIFT_HOMEDIR/app_root/dependencies; wget https://nodejs.org/dist/v6.3.0/node-v6.3.0-linux-x64.tar.xz; tar xf node-v6.3.0-linux-x64.tar.xz; rm node-v6.3.0-linux-x64.tar.xz Install the dev version. DO NOT install the stable version as that'll burn through your inodes like nothing else.
Change your PATH to include the the new node version export PATH="$OPENSHIFT_HOMEDIR/app_root/dependencies/node_modules/.bin/:$OPENSHIFT_HOMEDIR/app_root/dependencies/node/bin/:$PATH" Environment variables get reset whenever you disconnect from the server. You can change them permanently with rhc env set, but as this is only used before deployment, I recommend sticking this in the /.openshift/action_hooks/pre_build.
You also need to change the NPM_CONFIG_USERCONFIG variable. export NPM_CONFIG_USERCONFIG=$OPENSHIFT_HOMEDIR/app-root/build-dependencies/.npmrc. Once again, I recommend doing this in the pre_build hook.
At this point, you can change the cache without getting a permission denied error. npm config set cache "$OPENSHIFT_HOMEDIR/app_root/dependencies/.npm
You can now finally use npm install! Install the packages you need. Use the --prefix flag to install to the node_modules folder.
However, to use gulp, you need to have a gulp module installed in the place you're calling from, so npm install gulp WITHOUT the prefix flag.
You can now call gulp! However, your gulpfile will not not find the modules unless you edit your gulpfile to link to the dependencies folder you have set up. So instead of require('gulp-cssnano'), you'd have require([OPENSHIFT_HOMEDIR]/app_root/dependencies/node_modules/gulp-cssnano). I keep a separate gulpfile for Openshift to maintain my sanity.
Call gulp with your new gulpfile in pre_build.

Error message "ENOENT, no such file or directory"

I'm getting this error from my Node.js application:
ENOENT, no such file or directory '~/Desktop/MyApp/newversion/partials/navigation.jade'
I know the file is there because when I try to open the file using the exact copied and pasted path, it works. I also know the application is using the right directory because, well, it outputs it in the error.
I believe the previous answer is the correct answer to this problem but I was getting this error when I tried installing npm package (see below):
The fix for me was: npm init --yes
Tilde expansion is a shell thing. Write the proper pathname (probably /home/yourusername/Desktop/etcetcetc) or use
process.env.HOME + '/Desktop/blahblahblah'
I was also plagued by this error, and after trying all the other answers, magically found the following solution:
Delete file package-lock.json and the node_modules folder, and then run npm install again.
If that doesn't work, try running these in order:
npm install
npm cache clean --force
npm install -g npm
npm install
(taken from #Thisuri's answer and #Mathias Falci's comment respectively)
And then re-deleting the above files and rerunning npm install.
It worked for me!
First try npm install. If the issue is not yet fixed, try the following one after the other.
npm cache clean, then
npm install -g npm , then
npm install. Finally
ng serve --o to run the project.
__dirname
Gives you the current Node.js application's root directory.
In your case, you'd use
__dirname + '/Desktop/MyApp/newversion/partials/navigation.jade';
See this answer:
How can I get the application base path from a module in Node.js?
I had that issue using the path module:
const path = require('path');
And also do not forget to create the uploads directory first period.
Specifically, rm yarn.lock and then yarn install fixed this for me.
For those running Laravel Mix with npm run watch, just terminate the script and run the command again.
For me, it had my code folder in Dropbox on Windows 10. During the build process Dropbox would flip out over having more than 500,000 files. I moved my folder out and now it builds fine!
When this happened to me, it was when trying to run Karma tests in an Angular project. The tsconfig.spec.js file turned out to be incorrect. It was basically pointing to the wrong directory, and so the error was simply trying to tell me this.
For example, we had ../tsconfig.json instead of ./tsconfig.json, so the runner was looking for tests in the wrong folder. This may be a different use case from the OP, but the same error message brought me here and led me down the rabbit hole of trying the npm install solutions to no avail.
It usually occurs due to a mismatch in the npm version used while creating the package-lock.json that currently exist and the one you are using now.
Removing the package-lock.json and running npm install worked for me.
Sometimes you are just not in the right directory. Check that once and try "npm start" again.
Reason: I have the same issue, where a few guys work on one project and change package dependencies.
Solution: Just kill file package-lock.json and run npm i again
In my case, I was running the terminal in the wrong folder. Please make sure that you navigate to the folder containing your code (App.js and others) and then use a command prompt (for Windows) to open the code. I am using Visual Studio Code, so it is to type "code." after I have opened the command prompt in the exact folder where my code is in.
I ran into this upgrading a Phoenix app to 1.6, which does not use Node.js, so in fact it is not needed. However, elixir_buildpack.config had a reference to phoenix_static_buildpack.config, which defined node. Remove the reference, and the error goes away.
My problem was that I didn't have a package.json file in my working directory.
Another possibility is that you are missing an .npmrc file if you are pulling any packages that are not publicly available.
You will need to add an .npmrc file at the root directory and add the private/internal registry inside of the .npmrc file like this:
registry=http://private.package.source/secret/npm-packages/

Resources