【问题标题】:error with gulp-ng-annoate, couldn't process source due to parse errorgulp-ng-annoate 出错,由于解析错误而无法处理源代码
【发布时间】:2015-04-23 07:48:42
【问题描述】:

我遇到了由 gulp-ng-annoate 生成的错误的问题。

错误信息是

错误:app.js:错误:由于解析错误而无法处理源代码

我发现另一个线程似乎与我有同样的问题,但该答案对我不起作用。 the other thread

这是我的 gulp 文件和我正在尝试执行任务的文件。

gulpfile.js

var gulp = require('gulp')
var concat = require('gulp-concat')
//var uglify = require('gulp-uglify')
var ngAnnotate = require('gulp-ng-annotate')

gulp.task('js', function(){
    gulp.src(['ng/module.js', 'ng/**/*.js'])
        .pipe(concat('app.js'))
        .pipe(ngAnnotate())
        //.pipe(uglify())
        .pipe(gulp.dest('assets'))
})

以及我尝试连接/ngAnnotate 的文件

module.js

angular.module('app', [])

posts.ctrl.js

angular.module('app')
.controller('PostCtrl', function($scope, PostsSvc){
    $scope.addPost = function(){
        if ($scope.postBody){
            PostsSvc.create({
                username: 'dickeyxxx',
                body: $scope.postBody
            }).success(function(post){
                $scope.posts.unshift(post)
                $scope.postBody = null
            })
        }
    }

    PostsSvc.fetch().success(function(posts){
        $scope.posts = posts
    })
})

posts.svc.js

angular.module('app')
.service('PostsSvc', ['$http', function ($http){
    this.fetch = function(){
        return $http.get('/api/posts')
    }
    this.create = function(post){
        return $http.post('/api/posts', post)
    }
}])

可能出了什么问题..?

【问题讨论】:

    标签: javascript angularjs gulp mean-stack


    【解决方案1】:

    问题在于您将. 而非, 用于分隔对象。

    另外,别忘了; 结束你的行。

    【讨论】:

    • 我不确定您指的是哪个文件的哪一行“放置一个 . 而不是一个 , 来分隔对象”?我会假设 JS 不允许放 ;除非需要,否则到行尾?
    • 问题出在这里:PostsSvc.create({ username: 'dickeyxxx'. body: $scope.postBody})。添加; 是最简洁的JS编写方式,如果您是在1行中压缩代码,省略;会出现一些问题
    猜你喜欢
    • 2021-01-10
    • 1970-01-01
    • 1970-01-01
    • 2021-05-22
    • 1970-01-01
    • 1970-01-01
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多