我正在尝试设置一个包含以下内容的本地开发环境:
synced_folder
传递给vagrant 背景:
我已经在Ubuntu 16.04笔记本电脑上开发了一个vue CLI 3项目,该项目运行良好,但是,我希望将其移至无用的盒子内,以保持本地计算机整洁。我目前使用yarn run serve
效果很好。我希望能够在新的无业游民的开发环境中运行此命令。
问题/问题摘要:
vue
依赖项后找不到该命令yarn run serve
时,权限问题被纱线吐出fsevents@1.2.4
时有一条yarn global add @vue/cli
消息设置本地开发环境:
Vagrantfile
:
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.define "webserver_dev" do |webserver_dev|
webserver_dev.vm.box = "ubuntu/xenial64"
webserver_dev.vm.network "private_network", ip: "192.168.33.10"
webserver_dev.vm.network "forwarded_port", guest: 80, host: 8888
webserver_dev.vm.network "forwarded_port", guest: 8080, host: 8080
webserver_dev.vm.hostname = "develop.dev"
webserver_dev.vm.synced_folder ".", "/var/www", :mount_options => ["dmode=777", "fmode=666"]
webserver_dev.ssh.forward_agent = true
webserver_dev.vm.provider "virtualbox" do |vb|
vb.memory = "1824"
vb.cpus = "2"
end
end
end
提供无业游民的盒子:ubuntu/xenial64 (virtualbox, 20180802.0.0)
:
sudo apt update && sudo apt upgrade
sudo apt install build-essential libssl-dev -y
# install node and npm:
cd ~
curl -sL https://deb.nodesource.com/setup_10.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh
# install yarn
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
sudo apt-get update && sudo apt-get install yarn
# Show installed versions
yarn -v (outputs 1.9.4)
node -v (outputs v10.9.0)
npm -v (outputs 6.2.0)
问题/问题输出:
当我导航到现有的vue项目文件夹并在vagrant ssh中运行yarn run serve
时,出现以下错误:
yarn run v1.9.4
$ vue-cli-service serve
/bin/sh: 1: vue-cli-service: Permission denied
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
当我运行sudo yarn run serve
时
(我本来不必以root用户身份运行它,但:)
yarn run v1.9.4
$ vue-cli-service serve
/bin/sh: 1: vue-cli-service: Permission denied
error Command failed with exit code 126.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
运行vue --version
vagrant@cc:~$ vue --version
No command 'vue' found, did you mean:
Command 'vpe' from package 'texlive-latex-extra' (universe)
vue: command not found
运行yarn global add @vue/cli
的输出
如官方的vue-cli安装documentation
所示
注意:我收到的fsevents@1.2.4
消息。这可能是导致问题的原因吗?
vagrant@cu:~$ yarn global add @vue/cli
yarn global v1.9.4
[1/4] Resolving packages...
[2/4] Fetching packages...
[----------------------------------------------------------------------------------------------------------------------------------------] 0/617(node:7694) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
info fsevents@1.2.4: The platform "linux" is incompatible with this module.
info "fsevents@1.2.4" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "@vue/cli@3.0.1" with binaries:
- vue
Done in 58.25s.
摘要:
有没有人能够实现本地开发环境,从而可以在其中成功运行yarn run serve
并在其主机上访问结果?
我很想知道其他开发人员如何对vue js项目进行本地开发,这些项目还具有需要反向代理的其他服务(例如,在不同端口上运行的node js应用程序)。
我花了很多时间试图将其设置为无效。也许这些工具不能很好地配合使用。如果您认为可以提供帮助,我将不胜感激。谢谢
答案 0 :(得分:1)
临时解决方法:-受此post
的启发进一步的故障排除后,我发现问题肯定是与权限相关的问题(与vue-cli不相关)。
我认为我的游民使用VirtualBox时,出现了VirtualBox问题,该问题与主机上同步文件夹中的符号链接有关,可能会更改权限并阻止chmod
命令对文件产生任何影响。就我而言,node_modules / .bin目录中的execute标志是不可执行的。
对于有类似问题的任何人,这里是我目前对这个问题的解决办法(当前解决方法)(请帮个忙,请阅读https://github.com/hashicorp/vagrant/issues/713,希望早点找到它!):
1)将项目package.json
复制到:yarn全局目录:/home/vagrant/.config/yarn/global/
cp /var/www/project/package.json /home/vagrant/.config/yarn/global/
2)在yarn用户目录中全局安装项目依赖项:
cd /home/vagrant/.config/yarn/global
yarn install
3)现在返回项目并运行yarn run serve
可以正常工作,因为它使用了具有正确可执行权限的/home/vagrant/.config/yarn/global/node_modules/.bin/
中的node_modules。
cd /var/www/project/package.json
yarn run serve
问题原因示例:
1)将目录更改为您的项目,并使用ls -l查看权限:
cd /var/www/project/node_modules/.bin
ls -la
输出:
lrw-rw-rw- 1 vagrant vagrant 18 Aug 29 00:21 which -> ../which/bin/which
2)尝试使文件可执行:
chmod 777 ./which (adding sudo doesn't make this work either)
输出:
lrw-rw-rw- 1 vagrant vagrant 18 Aug 29 00:21 which -> ../which/bin/which
旧答案-无效:我现在使用的解决方案来自此处:Source
将此添加到Vagrantfile中可使符号链接正常工作。
我在主机和来宾计算机上使用ubuntu,因此无法确定它是否适用于Mac和Windows。
config.vm.provider "virtualbox" do |v|
v.customize ["setextradata", :id, "VBoxInternal2/SharedFoldersEnableSymlinksCreate/vagrant", "1"]
end
进一步阅读:
答案 1 :(得分:0)
在安装sudo
时,您需要使用vue-cli
。
https://cli.vuejs.org/guide/installation.html的vue-cli
文档指出:
要安装新软件包,请使用以下命令之一。 您 需要管理员特权才能执行这些操作,除非npm是 通过Node.js版本管理器安装在系统上(例如n或 nvm)。
npm install -g @vue/cli # OR yarn global add @vue/cli