Expo + vagrant,metro bundle 不起作用
Expo + vagrant, metro bundle doesn't work
我创建了一个 VM 来处理 expo。我不能 运行 Metro Bundle 在我主机的 19002 端口上的浏览器中。流浪文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
REACT_NATIVE_PACKAGER_HOSTNAME = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "geerlingguy/ubuntu1804"
config.ssh.insert_key = false
config.vm.provider :virtualbox do |v|
v.name = "mobile-app"
v.memory = 2048
v.cpus = 1
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.synced_folder "./", "/home/vagrant/workspace", type: 'nfs', mount_options: ['nolock,vers=3,udp,noatime']
config.vm.hostname = "mobile-app"
config.vm.network :private_network, ip: "192.168.33.40"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 19000, host: 19000
config.vm.network "forwarded_port", guest: 19001, host: 19001
config.vm.network "forwarded_port", guest: 19002, host: 19002
config.vm.network "forwarded_port", guest: 19006, host: 19006
config.vm.provision "shell", path: "install.sh"
config.vm.provision "set_lan_ip", "type": "shell" do |installs|
installs.inline = "
echo 'export REACT_NATIVE_PACKAGER_HOSTNAME=#{REACT_NATIVE_PACKAGER_HOSTNAME}' >> /home/vagrant/.zshrc
"
end
end
当我运行npm start
看到世博会开始的信息。我可以看到 url 和二维码图像:
Starting project at /home/vagrant/workspace/app
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)
Starting Metro Bundler
当我运行localhost:19002和192.168.33.40:19002时,我看到:This site can’t be reached
。但是当我启动 expo start:web
并打开时:192.168.33.40:19006 工作正常...当我在来宾上 运行 curl localhost:19002
时,我可以看到 html,但是相同的 cmd在主机上获取:接收失败。 (192.168.33.40同样报错)
我检查了端口:
node 1116 vagrant 21u IPv4 21603 0t0 TCP 127.0.0.1:19002 (LISTEN)
node 1116 vagrant 22u IPv6 21661 0t0 TCP *:19000 (LISTEN)
node 1160 vagrant 20u IPv6 21720 0t0 TCP *:19001 (LISTEN)
网络活跃的地方:
node 1220 vagrant 22u IPv4 22679 0t0 TCP *:19006 (LISTEN)
我觉得可能是端口的问题。 19002 映射到本地主机 (127.0.0.1),但应允许在所有接口上使用。我可以在 expo 中设置它吗?
我的错误在哪里?
解决方法:
export EXPO_DEVTOOLS_LISTEN_ADDRESS=192.168.33.40
我使用了另一个参数,但这个是正确的...
我创建了一个 VM 来处理 expo。我不能 运行 Metro Bundle 在我主机的 19002 端口上的浏览器中。流浪文件:
# -*- mode: ruby -*-
# vi: set ft=ruby :
VAGRANTFILE_API_VERSION = "2"
REACT_NATIVE_PACKAGER_HOSTNAME = Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "geerlingguy/ubuntu1804"
config.ssh.insert_key = false
config.vm.provider :virtualbox do |v|
v.name = "mobile-app"
v.memory = 2048
v.cpus = 1
v.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
v.customize ["modifyvm", :id, "--ioapic", "on"]
end
config.vm.synced_folder "./", "/home/vagrant/workspace", type: 'nfs', mount_options: ['nolock,vers=3,udp,noatime']
config.vm.hostname = "mobile-app"
config.vm.network :private_network, ip: "192.168.33.40"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 19000, host: 19000
config.vm.network "forwarded_port", guest: 19001, host: 19001
config.vm.network "forwarded_port", guest: 19002, host: 19002
config.vm.network "forwarded_port", guest: 19006, host: 19006
config.vm.provision "shell", path: "install.sh"
config.vm.provision "set_lan_ip", "type": "shell" do |installs|
installs.inline = "
echo 'export REACT_NATIVE_PACKAGER_HOSTNAME=#{REACT_NATIVE_PACKAGER_HOSTNAME}' >> /home/vagrant/.zshrc
"
end
end
当我运行npm start
看到世博会开始的信息。我可以看到 url 和二维码图像:
Starting project at /home/vagrant/workspace/app
Expo DevTools is running at http://localhost:19002
Opening DevTools in the browser... (press shift-d to disable)
Starting Metro Bundler
当我运行localhost:19002和192.168.33.40:19002时,我看到:This site can’t be reached
。但是当我启动 expo start:web
并打开时:192.168.33.40:19006 工作正常...当我在来宾上 运行 curl localhost:19002
时,我可以看到 html,但是相同的 cmd在主机上获取:接收失败。 (192.168.33.40同样报错)
我检查了端口:
node 1116 vagrant 21u IPv4 21603 0t0 TCP 127.0.0.1:19002 (LISTEN)
node 1116 vagrant 22u IPv6 21661 0t0 TCP *:19000 (LISTEN)
node 1160 vagrant 20u IPv6 21720 0t0 TCP *:19001 (LISTEN)
网络活跃的地方:
node 1220 vagrant 22u IPv4 22679 0t0 TCP *:19006 (LISTEN)
我觉得可能是端口的问题。 19002 映射到本地主机 (127.0.0.1),但应允许在所有接口上使用。我可以在 expo 中设置它吗?
我的错误在哪里?
解决方法:
export EXPO_DEVTOOLS_LISTEN_ADDRESS=192.168.33.40
我使用了另一个参数,但这个是正确的...