2015-06-16 162 views
1

我有以下Gulp任務:咕嘟咕嘟任務

var gulp = require('gulp'); 
var browserify = require('browserify'); 
var reactify = require('reactify'); 
var source = require('vinyl-source-stream'); 
var uglify = require('gulp-uglify'); 
var buffer = require('vinyl-buffer'); 
var derequire = require('gulp-derequire'); 

gulp.task('build-scripts', function() { 
    var b = browserify(); 
    b.transform(reactify); 
    b.add('./Scripts/app/app.js'); 

    return b.bundle() 
    .pipe(source('./Scripts/build/bundle.js')) 
    .pipe(derequire()) 
    .pipe(buffer()) 
    .pipe(uglify()) 
    .pipe(gulp.dest('.')) 

}); 

gulp.task('default', ['build-scripts']); 

我通過任務運行資源管理器在VS2013運行此。當我通過​​安裝所有依賴項並運行任務時,一切都按預期工作。一旦我添加了package.json我收到以下錯誤:

\ReactAccordion\gulpfile.js" build-scripts 
[15:56:24] Using gulpfile ~\Documents\Visual Studio 2013\Projects\ReactAccordion\ReactAccordion\gulpfile.js 
[15:56:24] Starting 'build-scripts'... 
events.js:85 
     throw er; // Unhandled 'error' event 
      ^
Error: SyntaxError: Unexpected token  while parsing json file ReactAccordion\ReactAccordion\package.json 
    at ReactAccordion\node_modules\browserify\node_modules\module-deps\index.js:477:30 
    at fs.js:334:14 
    at FSReqWrap.oncomplete (fs.js:95:15) 
Process terminated with code 1. 

如果恢復軟件包之後我從溶液中取出package.json文件,任務完成再罰款。我試過搜索,但無法找到報告的類似問題。從查看JS文件,一切看起來都很好。

這是我package.json文件:

{ 
    "name": "ReactAccordion", 
    "version": "1.0.0", 
    "private": true, 
    "dependencies": { 
     "react": "0.13.3" 
    }, 
    "devDependencies": { 
     "gulp": "3.9.0", 
     "browserify": "~10.2.4", 
     "reactify": "1.1.1", 
     "vinyl-source-stream": "1.1.0", 
     "gulp-uglify": "1.2.0", 
     "vinyl-buffer": "1.0.0", 
     "gulp-derequire": "2.1.0" 
    } 
} 

回答

1

如果您使用Visual Studio那麼它將有一個BOM(字節順序標記)添加到它,這使得它無效JSON,創建一個JSON文件npm install cannot read package.json

嘗試使用記事本創建package.json文件。

+0

前一個想法。謝謝! –