【问题标题】:Why gulp-livereload causes "Uncaught SyntaxError: Unexpected token <"?为什么 gulp-livereload 会导致“Uncaught SyntaxError: Unexpected token <”?
【发布时间】:2014-09-26 13:51:01
【问题描述】:

在我的gulpfile.js 中,我将express 设置为始终返回index.html

var server = express();
server.use(livereload({ port: 35729 }));
server.use(express.static('./app'));
server.all('*', function(req, res) {
  res.sendFile('index.html', { root: './app' });
});

server.listen(8000);
refresh.listen(35729);

我第一次导航到localhost:8000 时一切正常。我的 Angular 路由重定向到 http://localhost:8000/home

但是,如果我刷新http://localhost:8000/home,我会在控制台中看到以下错误:

Uncaught SyntaxError: Unexpected token <

为什么会这样?

DEMO HERE

【问题讨论】:

    标签: angularjs gulp gulp-livereload


    【解决方案1】:

    这是由angular route 引起的错误。 index.html 中的脚本引用需要相对于根目录。否则将找不到。

    <script src="/bower_components/angular/angular.js"></script>
    <script src="/bower_components/angular-route/angular-route.js"></script>
    
    <script src="/app.js"></script>
    <script src="/home/home.js"></script>
    <script src="/home/home-controller.js"></script>
    <script src="/dashboard/dashboard.js"></script>
    <script src="/dashboard/dashboard-controller.js"></script>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-29
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多