tleunen / eslint-import-resolver-babel-module

Custom eslint resolve for babel-plugin-module-resolver
https://github.com/tleunen/babel-plugin-module-resolver
MIT License
248 stars 31 forks source link

Breaks on Node 6 #98

Closed franjohn21 closed 5 years ago

franjohn21 commented 5 years ago

This package's built code is shipping Object.getOwnPropertyDescriptors which is not supported in Node v6. https://node.green/#ES2017-features-Object-static-methods-Object-getOwnPropertyDescriptors

Since this repo is using babel-preset-env and targeting a Node version of 6, I wouldn't expect this to break and it may be indicative of an error in babel itself. E.g. potentially related to https://github.com/babel/babel/issues/9382

Code snippet that is breaking:

function _objectSpread(target) {
  for (let i = 1; i < arguments.length; i++) {
    if (i % 2) {
      var source = arguments[i] != null ? arguments[i] : {};
      let ownKeys = Object.keys(source);
      if (typeof Object.getOwnPropertySymbols === 'function') {
        ownKeys = ownKeys.concat(
          Object.getOwnPropertySymbols(source).filter(
            sym => Object.getOwnPropertyDescriptor(source, sym).enumerable
          )
        );
      }
      ownKeys.forEach(key => {
        _defineProperty(target, key, source[key]);
      });
    } else {
      Object.defineProperties(
        target,
        Object.getOwnPropertyDescriptors(arguments[i]) // <---- This is the problem
      );
    }
  }
  return target;
}

My current workaround is to import @babel/polyfill in my .eslintrc.js until we can upgrade our versions of Node.


Version Info

tleunen commented 5 years ago

Afaik, Object.getOwnPropertyDescriptor is supported in Node 6. (see https://node.green/#ES2015-misc-Object-static-methods-accept-primitives-Object-getOwnPropertyDescriptor)

The link you shared is for Object.getOwnPropertyDescriptors (with a trailing "s"), which, indeed is not part of node 6.

Are you sure it's breaking? The code run in node 6 on the CI without issue. Could you provide more info on the error maybe?

franjohn21 commented 5 years ago

^^ Good catch. The code I pasted uses both getOwnPropertyDescriptor and getOwnPropertyDescriptors however. I'll update my original description to reference the one that is actually problematic

tleunen commented 5 years ago

Oh my. I should have paid more attention. I believe they indeed fixed the issue in the latest version, because I cannot reproduce the issue when I recompile the code.

I'm on it to fix it and release a new version. Thanks for reporting the issue.

franjohn21 commented 5 years ago

@tleunen Really appreciate the fast turn around. Thank you!