Express.js,Node.js,EJS - Uncaught SyntaxError:意外的令牌<

3 ejs node.js express

1)我的索引页面有ejs:

 <%include ../includes/layout.ejs %>
 <h1>This is the index page, did layout come along?</h1>
Run Code Online (Sandbox Code Playgroud)

2)我的ejs布局页面:

 <!DOCTYPE html> <html>
 <head>
    <title>MultiVision</title> 
    <% include ../includes/styles.ejs %>
    <script type="text/javascript" rc="/vendor/jquery/dist/jquery.min.js"></script>
</head>
<body>
  <%include ../includes/scripts.ejs%>
</body> 
</html>
Run Code Online (Sandbox Code Playgroud)

3)我的脚本页面与ejs:

 <script src="/vendor/bootstrap/dist/js/bootstrap.js" type="text/javascript"></script> 
 <script src="/vendor/toastr/toastr.js" type="text/javascript"></script>
 <script src="/vendor/angular/angular.js"type="text/javascript"></script> 
 <script src="/vendor/angular-resource/angular-resource.js" type="text/javascript"></script> 
 <script src="/vendor/angular-route/angular-route.js" type="text/javascript"></script> 
 <script src="/app/app.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

但是,我始终会为每个脚本标记收到此错误:

Uncaught SyntaxError: Unexpected token <  ######.js
Run Code Online (Sandbox Code Playgroud)

将它们更改为cdn位置虽然有效,但这不是我想要的.

小智 5

我想如果我把它包含在我的server.js中会有所帮助:;)

  ....
  , path = require('path'),
  .....
  app.use(express.static(path.join(__dirname, 'public')));
Run Code Online (Sandbox Code Playgroud)

  • “*.js”文件未设置为静态服务,因此服务器返回 404 错误,浏览器尝试将其解析为 JavaScript。 (2认同)