0

这真让我抓狂。我负责开发并需要合并分支,但正是在我的机器上,只有某些东西不起作用。

我已经多次删除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']);

running 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

它们不一样!!!! 这怎么可能?我的意思是我在两台机器上使用了完全相同的命令,对每个人都是一样的,除了andpackage.json之外没有其他命令已经运行(我什至使用 gulp from )npm installgulp prodnode_modules/.bin/gulp

我唯一能想到的事情是: - 有一些二进制文件可能会导致问题 - 节点或 npm 版本?在此处使用节点 5.1 - 一些并发问题,因为我的 PC 使用的是 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"
  }
}
4

1 回答 1

1

将此添加到您的 package.json

“巴别塔”:{“预设”:[“es2015”]},

或者如果你有一个现有的 .babelrc

于 2016-10-30T20:16:39.637 回答