Is there a solution for npm install error in Larav

2020-07-24 03:56发布

问题:

  • Windows 10,
  • Homestead
  • VirtualBox 6.0.8,
  • Vagrant 2.2.5,
  • node v12.5.0,
  • npm v6.10.1

All i'm trying to do is npm install command inside fresh installed Laravel app, but i keep getting errors.

After googling for two days and trying everything i found as a possible solution for npm install error i decided to try one more time reinstalling everything in hope that would fix my issue with npm install but unfortunately that didn't help either.

I tried deleting node_modules,
cleaning npm cache,
sudo npm install,
sudo npm install --no-bin-links,
updating node and npm but both were at latest version already,
changing VagrantFile based on some posts i've seen around internet(that never worked because than i'd get an error when i use vagrant up),
reinstalling everything,
running bash as admin,

I can't even remember everything I've done. This became really exhausing.

My log is 17k+ lines long. I'll just post last part where error happens.

17734 verbose stack Error: ENOENT: no such file or directory, open '/home/vagrant/code/vue-test/node_modules/yargs/node_modules/yargs-parser/package.json.2655513948'
17735 verbose cwd /home/vagrant/code/vue-test
17736 verbose Linux 4.15.0-54-generic
17737 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "--no-bin-links"
17738 verbose node v12.5.0
17739 verbose npm  v6.10.1
17740 error path /home/vagrant/code/vue-test/node_modules/yargs/node_modules/yargs-parser/package.json.2655513948
17741 error code ENOENT
17742 error errno -2
17743 error syscall open
17744 error enoent ENOENT: no such file or directory, open '/home/vagrant/code/vue-test/node_modules/yargs/node_modules/yargs-parser/package.json.2655513948'
17745 error enoent This is related to npm not being able to find a file.
17746 verbose exit [ -2, true ]

My last hope is to ask if someone has a solution for this or i should just give up on Homestead.

回答1:

I have grappled with the exact same issue for the last two days, except that I run on macOS (10.14). Using yarn instead of npm has finally allowed me to compile properly (see the doc for installing the package: https://yarnpkg.com/lang/en/docs/install/#alternatives-stable). It is a package manager that can use the same package.json entry point as npm, and you can simply try to run yarn install to perform the same action as npm install (for more in depth comparison between the commands, you can check out this link: https://yarnpkg.com/lang/en/docs/migrating-from-npm/). To be sure, it does not fix the main issue with npm, but at least it should allow you to work on your project while waiting for a more sound answer.



回答2:

What I've done to circunvemt this error is to npm install in the host-machine rather than on the guest through vagrant ssh. It seems that it's a problem with Windows locking the files from what I've researched. What I've done to bypass it, is:

  1. vagrant halt
  2. Inside your host (Windows), go to the shared folder for the website that you set-up in the homestead.yaml file.
  3. Open cmd or git bash (as admin) from inside the folder (Shift+Right click or cd into it) and run npm install.
  4. Voilà


回答3:

vagrant halt

then just run npm, install && npm run dev, and it worked for me



回答4:

I had the same problem

npm install --force

It works for me



回答5:

i tried everything.. the only thing that will work for me, is setting up a samba server on my linux box... from this i can edit the files directly on my windows machine..

hope this helps