Node webpack dev server failing 'Cannot GET /' in vuejs project

心已入冬 提交于 2021-01-02 14:14:32

问题


I am getting a super unhelpful message 'Cannot GET /' printed to my browser when I run my node dev server through webpack. I am building a Vuejs application with the following:

  • VueJs structured in a way that was dicated by this Vue Template with my node scripts being identical to the default commands
  • Webpack config based on Vue Loader
  • Routes handled through Vue Router

I know this is not a great deal to go off but an idea of what is firing this error (Node? Webpack? Vue Router?) it would point me in the right direction and be greatly appreciated.


回答1:


I found myself in the same problem. In my case it was related to the use of Express with Vue.js. So I am leaving my solution in case anyone finds it useful

I added this code for handling the calls to my index.html file

app.route('/*')
    .get(function(req, res) {
          res.sendFile(path.join(__dirname + '/dist/index.html'));
});

module.exports = app;



回答2:


Node is throwing the error and make sure your vue router is configured properly,Cannot GET simply means you have not assigned a view to your url e.g on express we use app.use('/', your route) and on connect we use app.get or app.post All it's saying is there is no content/view assigned to that url.




回答3:


It turns out it was an issue with the vuejs webpack template I was working from: https://github.com/vuejs-templates/webpack

The build path was being used in the dev server configuration.

Made this pull request to fix the issue: https://github.com/vuejs-templates/webpack/pull/188#issuecomment-230968416




回答4:


I had this issue while running my app in dev. Adding this to the devServer of my webpack.dev.config file helped:

historyApiFallback: true

Answer by Jezperp here.




回答5:


If you are using express check that you have this line:

app.use(express.static('static'));

And that "static" matches with the folder specified in your vue.config.js

outputDir: path.resolve("../Server/static")


来源:https://stackoverflow.com/questions/38235561/node-webpack-dev-server-failing-cannot-get-in-vuejs-project

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!