Open sdwru opened 4 years ago
update:
have no idea now.
Also test: created vue2 project by @vue/cli@4.5.8
, and run serve
on my server, visited by allowedHosts
.
Please provide reproducible repo. I create a new project by @vue/cli@3.12.1 which depends on @vue/cli-service@3.12.1 but can't reproduce your problem.
Did this problem appear after you upgraded any dependencies?
I just tried devDependency @vue/cli-service@3.12.1
and HMR still works. I don't know about other versions. I just know that HMR does not work on @vue/cli-service@4.5.8
.
The problem appears to have been introduced starting in @vue/cli-service@4.2.0
and every version since then. The last version with working HMR is @vue/cli-service@4.1.2
. I added this new info to my original post.
Please note that I am using a remote server with:
devServer: {
host: '0.0.0.0',
...
}
I have not tested this with a server on localhost.
@sdwru How is your host (myhost.mydomain.com
) mapped to the dev server? Entry in your hosts file pointing at 127.0.0.1
or is there a separate server acting as a proxy?
@sdwru How is your host (
myhost.mydomain.com
) mapped to the dev server? Entry in your hosts file pointing at127.0.0.1
or is there a separate server acting as a proxy?
No mapping no proxy. No entry in hosts file. It's just a generic virtual Linux server with default settings. No firewall no selinux. I access the server at myhost.mydomain.com:8080
which is an A record that points to my IP address at my DNS provider like any other public server.
It works on @vue/cli-service@4.1.2
and does not seem to work on @vue/cli-service@4.2.0
or any version after that one.
This is my hosts file with the public ip obfuscated.
127.0.0.1 localhost.localdomain localhost localhost4.localdomain4 localhost4
# Auto-generated hostname. Please do not remove this comment.
xx.xx.xx.xx ce81test.local ce81test
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
There are some problems when using host 0.0.0.0
in remote development, will check it later
Hmm, for me it fails to auto-detect the IP for the network URL on my remote server so it can't connect, but if I specify the host in devServer.public
, it works.
@sdwru Mind moving your host from the allowedHosts
array to the public
field in devServer and check if that helps?
Edit: it does correctly detect my Server's IP, it just discards it because it's not a private one
If you set host to 0.0.0.0
webpack entries in development is
[
/path_to/node_modules/webpack-dev-server/client/index.js?http://`your_priviate_ip:port`/sockjs-node',
/path_to/node_modules/webpack/hot/dev-server.js',
'./src/main.js'
]
Besides, webpack-dev-server will inject entry dynamically, injected entry is
/path_to/node_modules/webpack-dev-server/client/index.js?http://0.0.0.0',
Since you are using remote development server. Browser can't establish websocket connection through your_priviate_ip:port
(should use your_public_ip:port or your domain:port)
However, the dynamic injected entry works. webpack-dev-server/client/index.js
create socketUrl based on window.location
since 0.0.0.0
was passed, so browser can establish websocket connection. HMR works.
since webpack-dev-server/client
is loaded twice, this bug was fixed by https://github.com/vuejs/vue-cli/pull/5069
So /path_to/node_modules/webpack-dev-server/client/index.js?http://
your_priviate_ip:port/sockjs-node',
won't let your HMR works.
I believe if user set host
(especially 0.0.0.0
), respect it, and create entry based on it rather than private_ip
.
Moreover, the public
config mentioned by @jonaskuske makes the solution more complete, since it doesn't try to guess the URL of the server based on window.location
. The priority of public
is higher than host
,
So workaround is
devServer: {
host: '0.0.0.0',
public: `your_domain:port`
}
Thanks @jonaskuske @fangbinwei
Adding
public: 'mydomain.com:port'
to devServer
appears to work.
Version
4.5.8
The problem appears to have been introduced starting in
@vue/cli-service@4.2.0
. HMR still works in@vue/cli-service@4.1.2
Environment info
Steps to reproduce
vue-cli-service serve
What is expected?
Changes to a File.vue file should be reflected in the browser without a reload
What is actually happening?
Changes are not shown until browser is reloaded
Downgrading to
@vue/cli-service v4.1.2
resolves the problemThis is my vue.confg.js