Error executing NPM INSTALL inside Homestead - laravel

We are developing an app in Laravel, and we created a new project, we have an error when trying to run NPM INSTALL inside Homestead.
**We are using:
Vagrant 2.2.9
NPM 6.14.10
Node 12.20.0
The last homestead version
We tried:
Deleting node_modules
Deleting composer.json.lock
Cleaning cache
Reinstalling the virtual machine with the last version
And other stackoverflows.
But the solutions dont work.
And we can't run npm install. The error is: no such file or directory open 'home/vagrant/code/testing/node_modules/yargs/node_modules/cliui/package.json.3695679736' This is related to npm not being able to find a file.
Can you help me please?
Thanks.

I found the solution, you need to:
install NFS in your local machine (sudo apt-get install nfs-kernel-server) if u are using ubuntu, check how to do it in windows.
add type: "nfs" in your Homestead.yaml after folder mapping
vagrant reload --provision
And thats it. trying npm install now is working ok!

Related

Issue with npm install using homestead on windows

[Edit:Solved]
Its working now with NFS protocol.
From Homestead directory command vagrant plugin install vagrant-winnfsd adds nfs support to vagrant on windows.
In Homestead.yaml file line type: "nfs" below folder mapping section.
vagrant reload --provision restars box and everything works fine.
Im having problem with npm. I know there are other ways to install npm, but Im trying to find solution to install it that way - using vagrant ssh.
Windows 10 Home
Vagrant 2.2.10
Virtual Box 6.1.14
Homestead 11.x
Using ssh Im trying to 'npm install' from fresh project directory. During installations Im having error -2:
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/code/project/node_modules/webpack-dev-server/node_modules/ansi-regex/package.json.360296631'
npm ERR! enoent This is related to npm not being able to find a file.
To be clear - npm is installed on ubuntu which is part of Homestead - runned on VM with vagrant using virtual box.
Hope some1 solved that issue. I found it could be a problem with some windows permissions. Im running everything as admin, was trying 'npm install --force' etc etc.
Thanks.
since you're using vagrant ssh, please try sudo npm install

Cannot compile Laravel assets on new Homestead install

UPDATE 3 (LATEST)
Per suggestion below (from justanothereddie), configuring the drive as NFS fixed the problem. I am not sure why though, so will leave the question open for a few more days.
UPDATE 2
Just purchased a new MacBook Pro, but the problem remains. I can run an npm install, provided the folder is not shared with the host. If it is shared with the host, it fails.
UPDATE 1
I have discovered that I can compile the Laravel assets if the drive I am working in is not shared with the host. I am running the distro's VirtualBox package, which is 6.1.10. The latest release is 6.1.12, so perhaps that will fix it.
EDIT:
Originally I thought this problem was related to Laravel Jetstream, but I now see that it is related to Laravel more broadly. I have done a vagrant destroy to remove the machine, and removed my Homestead directory, and reinstalled Homestead from scratch.
When I do a laravel new my_project is installs fine, but as soon as I issue npm install it fails with the same error message as below. I can not understand why no one else is reporting this. This is a very simple process which I have completed successfully about 100 times in the past, and the only thing I have not tried is new hardware or VirtualBox install.
ORIGINAL POST:
Did a vagrant destroy a few days ago and installed the new Homestead on my Ubuntu host (20.04.1). Trying to install Jetstream for the first time, the inertia stack, with --teams. Tried both the vagrant new method, and the composer method. Failed both times with the following error.
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/vagrant/code/ftmv2/node_modules/yargs/node_modules/yargs-parser/package.json.1863223755
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/vagrant/code/my_test/node_modules/yargs/node_modules/yargs-parser/package.json.1863223755'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
Removed the node_modules directory and retried npm_install, but outcome is the same.
Jetstream Version: ^1.2
Jetstream Stack: Inertia
Laravel Version: ^8.0
PHP Version: ^7.3
Laravel Installer Version: 4.0.3
NPM version: 6.14.8
Had the exact same issue on my MacBook Pro and added type: "nfs" to "folders" in my Homestead.yaml. Did a vagrant reload --provision and now npm will install and compile
I've suffered with this issue for a long time and it seems that the problem is using npm install as a vagrant user inside a laravel/homestead box so the main issue is one of permissions on a synced folder which is the main task of Homestead.yaml.
Referenced in: https://www.vagrantup.com/docs/synced-folders/nfs.html
There's two solutions for this problem:
One will enable you to work from homestead normally, and the other is just like a patch of sorts.
Insert the next line just below your folder mapping on Homestead.yaml
type: "nfs"
Documentation of that here: https://laravel.com/docs/8.x/homestead
Next option is just working from your system, that has all permissions since it "owns" the folder in wich you are working.
Instead of executing npm install inside vagrant go to the folder in your system (your computer) and use the command from there.
If you need to clean install your project use:
rm -rf node_modules
npm cache clean

npm ERR! code ENOENT npm ERR! syscall open

I am trying to install npm in a laravel homestead folder but i get these error messeges.
error messages in terminal
I've suffered with this issue for a long time and it seems that the problem is using npm install as a vagrant user inside a laravel/homestead box so the main issue is one of permissions on a synced folder which is the main task of Homestead.yaml.
Referenced in: https://www.vagrantup.com/docs/synced-folders/nfs.html
There's two solutions for this problem:
One will enable you to work from homestead normally, and the other is just like a patch of sorts.
Insert the next line just below your folder mapping on Homestead.yaml
type: "nfs"
Documentation of that here: https://laravel.com/docs/8.x/homestead
Next option is just working from your system, that has all permissions since it owns the folder in wich you are working.
Instead of executing npm install inside vagrant go to the folder in your system (your computer) and use the command from there.
If you need to clean install your project use:
rm -rf node_modules
npm cache clean
In terminal from Homestead directory type vagrant plugin install vagrant-winnfsd. After installing that plugin as said above add to Homestead.yaml file line type: "nfs" streight below folders mapping so it looks like:
folders:
- map: ~/your_path/projects_folder
to: /home/vagrant/code
type: "nfs"
Then in terminal from Homestead directory vagrant reload --provision, vagrant ssh, cd to your project folder cd code/project. If installation failed before you can delete node_modules folder with rm -rf node_modules and npm install & npm run dev again.

Laravel Composer Update Error - Permission Denied

I'm having error during updating composer. It's a Laravel 4 project which I've downloaded from .... and first time I updated it, it was fine and got updated. but due some reason I deleted that replace it with a fresh copy of that project, but now when I started to update it, it gives me the following error:
[ErrorException]
copy(/home/username/.composer/cache/files/symfony/security-core/3a27d7b34ee6
2cb0fdf5ad970e7777912ef4722f.zip): failed to open stream: Permission denied
In between first and second update of this composer I did the following:
Tried to installed Vagrant and homestead, but failed due to some internet connection problem.
Updated Composer failed
Uninstalled vagrant and reinstall composer.
Reinstalled Composer
Updated composer (success)
Tried to install vagrant and homestead (success)
Update composer (failed)
uninstalled vagrant
Reinstalled Composer
Update Composer (failed)
The above mentioned error is getting occured again and again. I also tried 'composer clearcache' but doesn't worked. One thing which I noticed that it's been 16-19 months I'm using composer and never heard of such errors, but since I tried to install vagrant it created hurdles and errors for me.
I'm using Ubuntu 15.04
Updating Laravel 4.0 project
Updating Laravel 5
both project got updated before installing vagrant and homestead, but not now.
/var/www is under the group of 'www-data' and 'username' also the part of this group.
Any help plz!!!!!!!!!!!!!!!
I found the solution. If you see the error then it would be clear that I don't had access to the:
"/home/username/.composer/cache/files/symfony/security-core/3a27d7b34ee62cb0fdf5ad970e7777912ef4722f.zip".
When I explore this directory, I found that its owner is 'root' or 'sudo'.
So I deleted the '.composer' directory and then started to update in my laravel project directory, every thing was fine and perfect! No problem at all!
sudo composer update
worked for me. it's a permission issue.
if it doesn't work then you can try to
delete '.composer' directory and composer update afterward.
I know its an old topic, but for mac users this might be useful, since commands in macOS are a little bit different from linux distros and I had a hard time figuring this out.
cd into ~ directory
sudo chmod -R 777 .composer
Done. Now you can install/update composer.
I had the same issue with a mac, Composer warn me about running commands with super user permissions, so I've just changed the owner of files directory in the repo /Users/MyUserName/.composer/cache like so:
sudo chown -R MyUserName files/
Hope this helps.
I just run sudo before an all when ok
sudo composer create-project laravel/laravel=5.3 /Users/peter/Sites/blog --prefer-dist

Gulp didn't install on Laravel Homestead VM (from Windows) and no node_modules folder exists in the directory with package.json?

I got Laravel Homestead up and running, except when I issue this ssh command:
gulp
I get this error:
Local gulp not found in ~/projects/laravel
Try running: npm install gulp
That's when I noticed there was no node_modules folder at all in this directory. Weird. Is this an issue where the paths were too long for Windows when I did a vagrant up? Since the host machine for this VM is Windows and I'm sharing folders with my VM (actually I'm not, but rather I'm using phpStorm's sync so that pages will load faster on the VM), when I do a npm install am I still going to encounter the problem? Hmm...I guess Taylor Otwell is using a Mac for development. Anybody have a solution to this?
You should first install node in your local machine.
Then, navigate to your project folder and delete node_modules directory.
Run on your local machine inside project directory:
npm install gulp --save-dev
Solved it!
Yes it appears to be that some of these paths from these package installs are too long for Windows. This means you can only install the gulp package after your VM is up. Here's what I did: (I also include a step for use with phpStorm already (since it will keep server pages loading faster on the VM)
SSH into the VM and create a folder called node_modules in your project's directory (the directory where package.json is).
In phpStorm, go to File > Settings > Build, Execution, Deployment > Deployment and click on the Excluded Paths tab. Click the Add deployment path button and add the folder node_modules from step 1.
SSH back into the VM and in your projects folder (should be directory folder with package.json) and run this command: npm install. This will install all packages listed in your package.json file locally to the directory you are in, and will put the necessary files into the folder node_modules.
Now run the gulp command: gulp
UPDATE:
If you really prefer file-sharing through a mounted folder, then I've created a Gist that will guide someone through all the challenges I faced and had to resolve, including how to successfully run npm install in the guest environment:
Laravel Homestead for Windows (includes fixes)

Resources