【问题标题】:Gulp: SyntaxError: Unexpected end of JSON inputGulp:SyntaxError:JSON 输入意外结束
【发布时间】:2017-04-24 14:51:16
【问题描述】:

我有一个 AngularJS 应用程序,为此我使用 bower、npm 和 gulp。这段代码几天前可以工作,不知道为什么,但是当我执行 gulp 命令时,我得到了以下信息:

gulp minifycss;

错误:

 SyntaxError: Unexpected end of JSON input
at Object.parse (native)
at module.exports (..\node_modules\main-bower-files\lib\index.js:48:43)
at Gulp.<anonymous> (..\gulpfile.js:72:33)
at module.exports (..\node_modules\orchestrator\lib\runTask.js:34:7)
at Gulp.Orchestrator._runTask (..\node_modules\orchestrator\index.js:273:3)
at Gulp.Orchestrator._runStep (..\node_modules\orchestrator\index.js:214:10)
at Gulp.Orchestrator.start (..\node_modules\orchestrator\index.js:134:8)
at C:\Users\bgi5\AppData\Roaming\npm\node_modules\gulp\bin\gulp.js:129:20
at _combinedTickCallback (internal/process/next_tick.js:73:7)
at process._tickCallback (internal/process/next_tick.js:104:9)

Gulp 代码:

var cleanCss = require('gulp-clean-css'),  
filter = require('gulp-filter'),
concat = require('gulp-concat'),
merge = require('merge-stream'),
bowerFiles = require('main-bower-files');
var config = {
paths: {
    src: './src',
    build: './build',
    bower: './bower_components'
}
};
gulp.task('minifyCss', function () {
var v= gulp.src(bowerFiles())
    .pipe(filter(['**/*.css']))
    .pipe(concat('v.css'))
    .pipe(cleanCss({debug: true}))
    .pipe(gulp.dest(config.paths.build + '/styles'));

var a= gulp.src(config.paths.src + '/**/*.css')
    .pipe(concat('a.css'))
    .pipe(cleanCss({debug: true}))
    .pipe(gulp.dest(config.paths.build + '/styles'));

return merge(v, a);
});

【问题讨论】:

    标签: angularjs gulp bower gulp-uglify main-bower-files


    【解决方案1】:

    这是由代码中的变量 bowerFiles 引起的。

    bowerFiles = require('main-bower-files');

    由于某种原因,它没有从您安装的 bower 包中找到所需的 css 文件。由于错误说明了 JSON,我猜您的 bower 配置文件 .bowerrc 有问题。仔细检查它指向的 bower 目录是否正确。查看此link 以获取有关 .bowerrc 文件的更多信息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-08-22
      • 2016-08-05
      • 2018-01-23
      • 2020-07-10
      • 2020-09-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多