New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vue thinks local IP address is global, causing several issues #1616
Comments
The devserver is meant for local development and is not accessible from outside by default. However, you can adjust this behaviour in vue.config.js with the https://cli.vuejs.org/config/#devserver Options to look into: https://webpack.js.org/configuration/dev-server/#devserver-disablehostcheck https://webpack.js.org/configuration/dev-server/#devserver-host |
Thanks for you reply. |
the devServer options have their own options property in vue.config.js because we process them internally before handing them to the devserver: module.exports = {
configureWebpack: {
// other webpack options to merge in ...
},
// devServer Options don't belong into `configureWebpack`
devServer: {
host: '0.0.0.0',
hot: true,
disableHostCheck: true,
},
}; |
Oops, my fault... thanks for pointing out.
|
The code you mention should not be running if I set the |
So you mean the right configuration is not $ npm run serve
> anne3@0.1.0 serve /***/***/***/***
> vue-cli-service serve
INFO Starting development server...
Starting type checking service...
Using 1 worker with 2048MB memory limit
10% building modules 1/1 modules 0 activeevents.js:183
throw er; // Unhandled 'error' event
^
Error: listen EADDRNOTAVAIL ggg.ggg.ggg.ggg:8080
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at Server.setupListenHandle [as _listen2] (net.js:1338:19)
at listenInCluster (net.js:1396:12)
at GetAddrInfoReqWrap.doListen [as callback] (net.js:1505:7)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! anne3@0.1.0 serve: `vue-cli-service serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the anne3@0.1.0 serve script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/ec2-user/.npm/_logs/2018-06-21T07_43_06_386Z-debug.log |
Hm, I see... Side question: why do you want to run the development server on a remote machine? |
Well, I thought that occurs everywhere... at least in the companies I have been at :) Out of curiosity, when you develop on localhost, then I wonder why HMR wants to connect to the server via local network address, not localhost. |
So first, a small update. the devServer: {
// setting host should not be necessary
// host: '0.0.0.0:8080'
public: '0.0.0.0:8080'
disableHostCheck: true,
},
It doesn't do that for me. An that's a different scenario that yours, where you do access from an external host, right? |
I think setting
Based on my testing, the address given for Something that can be confusing is the auto-detection can end up using an IP from a purely local network adapter. For example, the
That The What exactly is the It also seems like the server binds to // vue.config.js
module.exports = {
devServer: {
host: '0.0.0.0',
},
} gives:
The app is still accessible from my LAN. If I set
However, the app is only accessible at Is the goal to avoid giving the user
Then, if
Otherwise:
The
with the output:
@kissge Try this // vue.config.js
module.exports = {
devServer: {
host: '0.0.0.0',
port: '8080',
public: 'mydomain.example.com:8080',
},
} Note that you must be able to connect to @LinusBorg A decent use case for wanting to do this is to have a site / app running on an alternate device during development. For example, at the moment I'm playing around with an app on a Raspberry Pi. The screen is fairly low resolution (800x480), the color reproduction isn't comparable to the monitor I use for development, and I want to test the touch input. It's useful to have it plugged in beside me auto-reloading as I make changes. |
So, the inference for public network API has its limitations, but you can always explicitly specify the public URL to use with In ccc90c9 I've also added:
|
I think |
@lux-lth yeah, that was my confusion here too. It took quite a bit of research over GH issues and webpack questions to find out that one can just create a vue.config.js in the root of the project, with the contents that Linus suggested above. Thanks! |
I've found this issue looking for a solution where a device connected through Chrome's port forwarding was trying to connect to the hot reloading module in my local IP address (192.168.0.250) instead of localhost (Chrome port forwarding only works on localhost), causing the hot reloading module not to work on mobile. Based on what is written in this issue, my vue.config.js: const fs = require("fs");
const path = require("path");
const port = 18001; // Easy to change the port here
function resolvePath(dir)
{
return path.join(__dirname, "certificates", dir); // c:\project\certificates contains my self-signed HTTPs certificates
}
module.exports =
{
lintOnSave: false,
baseUrl: `https://localhost:${port}/`,
devServer:
{
https: // Only needed if you want https (I need them for location and web notifications)
{
key: fs.readFileSync(resolvePath("server.key")),
cert: fs.readFileSync(resolvePath("server.crt")),
ca: fs.readFileSync(resolvePath("server.pem.key"))
},
headers:
{
"Access-Control-Allow-Origin": "*"
},
overlay: true,
port, // This will take care of desktop machine
public: `0.0.0.0:${port}`, // This will take care of mobile device
disableHostCheck: true,
}
}; And it works (there is a huge warning on Android because of not trusted certificate, but that's another issue).
|
I think this is a bug, because it occurs when creating the default template with all defaults settings too: So I've run vue create hello-world --default
Vue CLI v3.2.1
✨ Creating project in /Users/piotrblazejewicz/git/pwa-builder-test/hello-world.
🗃 Initializing git repository...
⚙ Installing CLI plugins. This might take a while...
> fsevents@1.2.4 install /Users/piotrblazejewicz/git/pwa-builder-test/hello-world/node_modules/fsevents
> node install
[fsevents] Success: "/Users/piotrblazejewicz/git/pwa-builder-test/hello-world/node_modules/fsevents/lib/binding/Release/node-v59-darwin-x64/fse.node" is installed via remote
> yorkie@2.0.0 install /Users/piotrblazejewicz/git/pwa-builder-test/hello-world/node_modules/yorkie
> node bin/install.js
setting up Git hooks
done
added 1177 packages from 761 contributors and audited 14846 packages in 41.504s
found 0 vulnerabilities
🚀 Invoking generators...
📦 Installing additional dependencies...
added 26 packages from 23 contributors, updated 2 packages, moved 5 packages and audited 15136 packages in 13.117s
found 0 vulnerabilities
⚓ Running completion hooks...
📄 Generating README.md...
🎉 Successfully created project hello-world.
👉 Get started with the following commands:
$ cd hello-world
$ npm run serve and I've ended using Google to learn that I have to add Thanks! |
Not sure why yet, but after upgrade to
on 3.5.0 was working fine without touching |
Same issue with @vue/cli-service@3.6.0 |
Same issue here with an app inside VirtualBox |
Cases like this happen if you are running another app (e.g. Laravel via the artisan CLI) concurrently on your network that uses the same port as your Vuejs app. So basically it is listening to both your local and network IP when running the app in your dev environment. if you are working on Vue CLI, may not be able to configure webpack dev server directly.
|
Maybe i don't get something essential but i think i encounter some behaviour with cli version4 that seems to be the same thing and nothing here on this page seems to completely help: I do a standard
Calling it in the browser the page gets loaded fine but the console gives me (cross-origin) warnings: xxx.xxx.xxx.xxx:8081/sockjs-node/info?t=1579649486458 could not be read, one by one, adding up. Then, after adding a vue.config.js file in the root folder with the content suggested by phalconVee
and the warnings are gone. [HMR] Waiting for update signal from WDS... log.js:24 XHRGEThttp://localhost:8081/sockjs-node/info?t=1579650320833 What would i have to do to have no extra network participating at all? |
In Ubuntu 18.04.03 Server Edition and with vue@2.6.11, I'm getting these error messages, when deploying my starting-page of webapp with vue.js: npm run serve
GET https://192.168.1.7:8081/sockjs-node/info?t=1579780726858 This is my vue.config.js file :
How to solve the problem? |
In my case I had |
@alex700 in which file exactly you had HOST env variable set to production, which caused sockjs error? |
@marcoippolito |
Thanks @alex700 . I guess I miss something because I didn't specify any .env file |
Worked like magic for me :-) |
Wanted to leave a comment here for folks arriving from Google looking to get this working with an ngrok tunnel. Ngrok configuration is standard http tunnel. The final working dev server config for us ended up being
This ought to allow you to access via tunnel (including https) with hot reloading working and no CORS issues. |
Version
3.0.0-rc.2
Reproduction link
https://github.com/kissge/vue-cli-bug
Steps to reproduce
vue create
to start a project, on a remote machine (say, AWS EC2 instance)npm run serve
What is expected?
What is actually happening?
I also tried tweaking webpack config from vue.config.js, with no luck.
The text was updated successfully, but these errors were encountered: