我快疯了。我负责开发,需要做分支合并,但正是在我的机器上只有一些东西不工作。
我已经多次删除node_modules
并运行npm install
,甚至完全克隆了repo并重新设置了所有内容,但我总是会遇到同样的问题。
有人将代码与ES6合并,所以我们需要对其进行编译,因为minifier插件不能与ES6代码一起工作。
我们用gulp-babel
var
gulp = require('gulp')
//more requires
, babel = require('gulp-babel')
var libs_js = [
//list of javascripts
]
gulp.task('js-build', function () {
gulp.src(libs_js)
.pipe(sourcemaps.init())
.pipe(ngAnnotate())
.pipe(running_task != 'js-build' ? _bypass() : tap(function(f) { f.contents = new Buffer('document.write('<script src="' + f.path.replace(process.cwd(), '')
.replaceAll('\','/') // fix paths for windows
+ '"></script>')') }))
.pipe(concat(pkg.name + '.js', {newLine: 'n;'}))
.pipe(babel({presets: ['es2015'],compact: false}))
.pipe(running_task == 'js-build' ? _bypass() : uglify())
.pipe(sourcemaps.write('.'))
.pipe(gulp.dest('dist'))
.on('end', function () {
console.log('[' + new Date + '] js compiled')
})
});
//other gulp targets
gulp.task('prod', ['js-build', 'css', 'sass', 'assets', 'libs']);
运行gulp prod
,对每个人都有效,但对我来说,我得到:
...
[Wed Oct 26 2016 22:05:51 GMT-0500 (COT)] asset completedd
events.js:141
throw er; // Unhandled 'error' event
^
Error: Couldn't find preset "latest" relative to directory "/home/me/prj/src"
at /home/me/prj/src/frontend/node_modules/babel-core/lib/transformation/file/options/option-manager.js:299:19
首先,为什么抱怨"latest"
,如果在代码中我们使用es2015
。我在另一台电脑上运行了所有程序,发现了一些令人惊讶的事情:
在我的机器上:
>$ npm list | grep babel
├─┬ babel-preset-es2015@6.18.0
│ ├─┬ babel-plugin-check-es2015-constants@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├── babel-plugin-transform-es2015-arrow-functions@6.8.0
│ ├── babel-plugin-transform-es2015-block-scoped-functions@6.8.0
│ ├─┬ babel-plugin-transform-es2015-block-scoping@6.18.0
│ │ ├─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-classes@6.18.0
│ │ ├─┬ babel-helper-define-map@6.18.0
│ │ ├── babel-helper-function-name@6.18.0
│ │ ├── babel-helper-optimise-call-expression@6.18.0
│ │ ├── babel-helper-replace-supers@6.18.0
│ │ └── babel-messages@6.8.0
│ ├── babel-plugin-transform-es2015-computed-properties@6.8.0
│ ├── babel-plugin-transform-es2015-destructuring@6.18.0
│ ├── babel-plugin-transform-es2015-duplicate-keys@6.8.0
│ ├── babel-plugin-transform-es2015-for-of@6.18.0
│ ├── babel-plugin-transform-es2015-function-name@6.9.0
│ ├── babel-plugin-transform-es2015-literals@6.8.0
│ ├── babel-plugin-transform-es2015-modules-amd@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-commonjs@6.18.0
│ │ └── babel-plugin-transform-strict-mode@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-systemjs@6.18.0
│ │ └── babel-helper-hoist-variables@6.18.0
│ ├── babel-plugin-transform-es2015-modules-umd@6.18.0
│ ├── babel-plugin-transform-es2015-object-super@6.8.0
│ ├─┬ babel-plugin-transform-es2015-parameters@6.18.0
│ │ ├── babel-helper-call-delegate@6.18.0
│ │ └── babel-helper-get-function-arity@6.18.0
│ ├── babel-plugin-transform-es2015-shorthand-properties@6.18.0
│ ├── babel-plugin-transform-es2015-spread@6.8.0
│ ├─┬ babel-plugin-transform-es2015-sticky-regex@6.8.0
│ │ └─┬ babel-helper-regex@6.18.0
│ ├── babel-plugin-transform-es2015-template-literals@6.8.0
│ ├── babel-plugin-transform-es2015-typeof-symbol@6.18.0
│ ├─┬ babel-plugin-transform-es2015-unicode-regex@6.11.0
│ └─┬ babel-plugin-transform-regenerator@6.16.1
├─┬ gulp-babel@6.1.2
│ ├─┬ babel-core@6.18.0
│ │ ├─┬ babel-code-frame@6.16.0
│ │ ├─┬ babel-generator@6.18.0
│ │ ├── babel-helpers@6.16.0
│ │ ├─┬ babel-register@6.18.0
另一个:
$ npm list | grep babel
├─┬ babel-preset-es2015@6.18.0
│ ├─┬ babel-plugin-check-es2015-constants@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-arrow-functions@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-block-scoped-functions@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-block-scoping@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ ├─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-classes@6.18.0
│ │ ├─┬ babel-helper-define-map@6.18.0
│ │ ├─┬ babel-helper-function-name@6.18.0
│ │ │ └── babel-helper-get-function-arity@6.18.0
│ │ ├── babel-helper-optimise-call-expression@6.18.0
│ │ ├── babel-helper-replace-supers@6.18.0
│ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ ├─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-computed-properties@6.8.0
│ │ ├─┬ babel-helper-define-map@6.18.0
│ │ │ ├─┬ babel-helper-function-name@6.18.0
│ │ │ │ ├── babel-helper-get-function-arity@6.18.0
│ │ │ │ └─┬ babel-traverse@6.18.0
│ │ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ │ ├── babel-messages@6.8.0
│ │ │ ├─┬ babel-types@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-destructuring@6.18.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-duplicate-keys@6.8.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-for-of@6.18.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-function-name@6.9.0
│ │ ├─┬ babel-helper-function-name@6.18.0
│ │ │ ├── babel-helper-get-function-arity@6.18.0
│ │ │ ├─┬ babel-template@6.16.0
│ │ │ └─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-literals@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-amd@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-commonjs@6.18.0
│ │ ├── babel-plugin-transform-strict-mode@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ ├─┬ babel-template@6.16.0
│ │ │ ├─┬ babel-traverse@6.18.0
│ │ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ │ ├── babel-messages@6.8.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-systemjs@6.18.0
│ │ ├─┬ babel-helper-hoist-variables@6.18.0
│ │ │ └─┬ babel-types@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-modules-umd@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-object-super@6.8.0
│ │ ├─┬ babel-helper-replace-supers@6.18.0
│ │ │ ├── babel-helper-optimise-call-expression@6.18.0
│ │ │ ├── babel-messages@6.8.0
│ │ │ ├─┬ babel-template@6.16.0
│ │ │ ├─┬ babel-traverse@6.18.0
│ │ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ └─┬ babel-types@6.18.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-parameters@6.18.0
│ │ ├─┬ babel-helper-call-delegate@6.18.0
│ │ │ └── babel-helper-hoist-variables@6.18.0
│ │ ├── babel-helper-get-function-arity@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ ├─┬ babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ │ ├─┬ babel-code-frame@6.16.0
│ │ │ ├── babel-messages@6.8.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-shorthand-properties@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-spread@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-sticky-regex@6.8.0
│ │ ├─┬ babel-helper-regex@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ └─┬ babel-types@6.18.0
│ ├─┬ babel-plugin-transform-es2015-template-literals@6.8.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-typeof-symbol@6.18.0
│ │ └─┬ babel-runtime@6.18.0
│ ├─┬ babel-plugin-transform-es2015-unicode-regex@6.11.0
│ │ ├─┬ babel-helper-regex@6.18.0
│ │ │ ├─┬ babel-types@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ └─┬ babel-plugin-transform-regenerator@6.16.1
│ ├─┬ babel-runtime@6.18.0
│ ├─┬ babel-types@6.18.0
├─┬ gulp-babel@6.1.2
│ ├─┬ babel-core@6.18.0
│ │ ├─┬ babel-code-frame@6.16.0
│ │ ├─┬ babel-generator@6.18.0
│ │ ├── babel-helpers@6.16.0
│ │ ├── babel-messages@6.8.0
│ │ ├─┬ babel-register@6.18.0
│ │ ├─┬ babel-runtime@6.18.0
│ │ ├── babel-template@6.16.0
│ │ ├─┬ babel-traverse@6.18.0
│ │ ├─┬ babel-types@6.18.0
它们是不同的!!!!这是怎么可能的?我的意思是我在两台机器上使用了完全相同的命令,package.json
对每个人都是一样的,并且除了npm install
和gulp prod
之外没有不同的命令已经运行(我甚至使用了node_modules/.bin/gulp
的gulp)
我唯一能想到的是:-有一些二进制的东西可能会引起问题-节点或NPM版本?这里使用节点5.1-一些并发问题,因为我的电脑使用SSD存储?
参考package.json
{
"name": "Proj",
"version": "0.1.0",
"description": "",
"main": "index.js",
"scripts": {
"heroku-postbuild": "bower install && gulp prod"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel-preset-es2015": "^6.18.0",
"concurrently": "^2.2.0",
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-concat": "^2.6.0",
"jasmine-core": "^2.4.1",
"karma": "^1.1.2",
"karma-coverage": "^1.1.1",
"karma-jasmine": "^1.0.2",
"karma-phantomjs-launcher": "^1.0.1",
"mkdirp": "^0.5.1"
},
"dependencies": {
"bower": "^1.7.9",
"colors": "^1.1.2",
"compression": "^1.6.2",
"es6-promise": "^3.2.1",
"express": "^4.14.0",
"fb-watchman": "^1.9.0",
"gulp": "^3.9.1",
"gulp-autoprefixer": "^3.1.1",
"gulp-concat": "^2.6.0",
"gulp-minify-css": "^1.2.4",
"gulp-ng-annotate": "^2.0.0",
"gulp-plumber": "^1.1.0",
"gulp-sass": "^2.3.2",
"gulp-sourcemaps": "^1.6.0",
"gulp-tap": "^0.1.3",
"gulp-uglify": "^2.0.0",
"request": "^2.74.0",
"uglify-js": "^2.7.4"
}
}
添加到package.json
"宝贝":{"预设":("es2015"]},