Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SyntaxError: expected expression, got '<' error - vue

When I developed my vue project in my local environment(run npm run dev command), for the first-page loading, there is no error. But when I hit the refresh button, the console output a "SyntaxError: expected expression, got '<'" error, and the hot reload is not work.

The index.html code

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <title>kmf</title>
  </head>
  <body>
    <div id="app">
    </div>
    <!-- built files will be auto injected -->
  <script type="text/javascript" src="app.js"></script></body>
</html>

But if I run npm run build and upload the file to the server. This error is not output. Does anyone know where the problem is?

like image 773
ChenLee Avatar asked Aug 03 '18 08:08

ChenLee


1 Answers

This usually means that your server (or the webpack hot reload) is using the same route to send back both .html and .js files. In your case, when the client asks for the .js script, it sends back the .html file, which indeed starts with the '<' character.

Try adding a relative path to your script, such as:

<script type="text/javascript" src="./app.js"></script>
like image 83
pierre Avatar answered Nov 05 '22 19:11

pierre