使用babel-preset-env定位节点8时,未聚合Array.prototype.values

时间:2017-12-17 11:47:00

标签: node.js babel babel-polyfill

使用babel-preset-env和目标节点8时,Babel不是polyfiiling array.values()。

.babelrc

{
  "presets": [
    ["env", {
      "targets": {
        "node": "8"
      },
      "useBuiltIns": true,
      "debug": true
    }]
  ]
}

代码:

import 'babel-polyfill';
const arr = [1,2,3];
console.log(arr.values);
const it = arr.values();
console.log('arr.values it next', it.next().value);

我使用npm脚本编译它:

"compile": "babel src --out-dir ./dist --source-maps",

,编译输出为:

  

babel src --out-dir ./dist --source-maps

babel-preset-env: `DEBUG` option

Using targets:
{
  "node": "8"
}

Modules transform: commonjs

Using plugins:
src/server.js -> dist/server.js

node dist / server.js输出:

undefined
error: uncaughtException and caused stop application   Error: TypeError: arr.values is not a function

当我尝试使用babel-node运行它或者在.babelrc中定位节点4时,奇怪的是,array.values是正确的polyfilled

编译输出:

> babel src --out-dir ./dist --source-maps

babel-preset-env: `DEBUG` option

Using targets:
{
  "node": "4"
}

Modules transform: commonjs

Using plugins:
  check-es2015-constants {"node":"4"}
  transform-es2015-arrow-functions {"node":"4"}
  transform-es2015-block-scoping {"node":"4"}
  transform-es2015-classes {"node":"4"}
  transform-es2015-destructuring {"node":"4"}
  transform-es2015-for-of {"node":"4"}
  transform-es2015-function-name {"node":"4"}
  transform-es2015-object-super {"node":"4"}
  transform-es2015-parameters {"node":"4"}
  transform-es2015-spread {"node":"4"}
  transform-es2015-sticky-regex {"node":"4"}
  transform-es2015-unicode-regex {"node":"4"}
  transform-regenerator {"node":"4"}
  transform-exponentiation-operator {"node":"4"}
  transform-async-to-generator {"node":"4"}
  syntax-trailing-function-commas {"node":"4"}

Using polyfills:
  es6.typed.array-buffer {"node":"4"}
  es6.typed.int8-array {"node":"4"}
  es6.typed.uint8-array {"node":"4"}
  es6.typed.uint8-clamped-array {"node":"4"}
  es6.typed.int16-array {"node":"4"}
  es6.typed.uint16-array {"node":"4"}
  es6.typed.int32-array {"node":"4"}
  es6.typed.uint32-array {"node":"4"}
  es6.typed.float32-array {"node":"4"}
  es6.typed.float64-array {"node":"4"}
  es6.map {"node":"4"}
  es6.set {"node":"4"}
  es6.weak-map {"node":"4"}
  es6.weak-set {"node":"4"}
  es6.reflect.apply {"node":"4"}
  es6.reflect.construct {"node":"4"}
  es6.reflect.define-property {"node":"4"}
  es6.reflect.delete-property {"node":"4"}
  es6.reflect.get {"node":"4"}
  es6.reflect.get-own-property-descriptor {"node":"4"}
  es6.reflect.get-prototype-of {"node":"4"}
  es6.reflect.has {"node":"4"}
  es6.reflect.is-extensible {"node":"4"}
  es6.reflect.own-keys {"node":"4"}
  es6.reflect.prevent-extensions {"node":"4"}
  es6.reflect.set {"node":"4"}
  es6.reflect.set-prototype-of {"node":"4"}
  es6.promise {"node":"4"}
  es6.symbol {"node":"4"}
  es6.function.name {"node":"4"}
  es6.regexp.flags {"node":"4"}
  es6.regexp.match {"node":"4"}
  es6.regexp.replace {"node":"4"}
  es6.regexp.split {"node":"4"}
  es6.regexp.search {"node":"4"}
  es6.array.from {"node":"4"}
  es7.array.includes {"node":"4"}
  es7.object.values {"node":"4"}
  es7.object.entries {"node":"4"}
  es7.object.get-own-property-descriptors {"node":"4"}
  es7.string.pad-start {"node":"4"}
  es7.string.pad-end {"node":"4"}

可能存在问题的任何想法?

0 个答案:

没有答案