我有以下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中的任务运行资源管理器运行它。当我通过npm cli
安装所有依赖项并运行任务时,一切都按预期工作。添加package.json
后,出现以下错误:
ReactAccordiongulpfile.js" build-scripts
[15:56:24] Using gulpfile ~DocumentsVisual Studio 2013ProjectsReactAccordionReactAccordiongulpfile.js
[15:56:24] Starting 'build-scripts'...
events.js:85
throw er; // Unhandled 'error' event
^
Error: SyntaxError: Unexpected token while parsing json file ReactAccordionReactAccordionpackage.json
at ReactAccordionnode_modulesbrowserifynode_modulesmodule-depsindex.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"
}
}
如果你使用Visual Studio创建一个json文件,那么它将添加一个BOM(字节顺序标记),这使得它无效的JSON,npm install无法读取package.json
请尝试使用记事本创建 package.json 文件。