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.
<!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?
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With