12

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:

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.

6 Answers 6

9

If you're experiencing this with Vite, make sure you ran just vite in your package.json script, NOT vite preview

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks that helped!
BTW to make vite preview work you first need to run vite build.
8

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 Comments

var path = require('path') just so it's clear - thanks! this fixed it 🙂
for anyone misunderstanding this, it needs to go in your server.js (or equivalent, wherever you import express). If you see an error in your browser window, you likely need to import path like @user1274820 mentioned. This fixed the issue for me!
1

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.

2 Comments

I just put the final touches on a pull request. Turns out it was to do with the paths the webpack config template I was working from: github.com/vuejs-templates/webpack/pull/188
Glad you figured it out
1

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

Comments

0

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.

Comments

0

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")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.