nrwl / nx

Smart Monorepos · Fast CI
https://nx.dev
MIT License
23.45k stars 2.33k forks source link

Npm workspace + React library should create browserslistrc with modern browser support #7080

Closed ArielGueta closed 2 years ago

ArielGueta commented 3 years ago

I'm creating a react buildable and publishable React library, and when I build it, it adds many unrelated code to the bundle:

var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};

var check = function (it) {
  return it && it.Math == Math && it;
};

// https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
var global$b =
  // eslint-disable-next-line es/no-global-this -- safe
  check(typeof globalThis == 'object' && globalThis) ||
  check(typeof window == 'object' && window) ||
  // eslint-disable-next-line no-restricted-globals -- safe
  check(typeof self == 'object' && self) ||
  check(typeof commonjsGlobal == 'object' && commonjsGlobal) ||
  // eslint-disable-next-line no-new-func -- fallback
  (function () { return this; })() || Function('return this')();

var objectGetOwnPropertyDescriptor = {};

var fails$6 = function (exec) {
  try {
    return !!exec();
  } catch (error) {
    return true;
  }
};

var fails$5 = fails$6;

// Detect IE8's incomplete defineProperty implementation
var descriptors = !fails$5(function () {
  // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
});

var objectPropertyIsEnumerable = {};

var $propertyIsEnumerable = {}.propertyIsEnumerable;
// eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;

// Nashorn ~ JDK8 bug
var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);

// `Object.prototype.propertyIsEnumerable` method implementation
// https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
objectPropertyIsEnumerable.f = NASHORN_BUG ? function propertyIsEnumerable(V) {
  var descriptor = getOwnPropertyDescriptor$1(this, V);
  return !!descriptor && descriptor.enumerable;
} : $propertyIsEnumerable;

var createPropertyDescriptor$2 = function (bitmap, value) {
  return {
    enumerable: !(bitmap & 1),
    configurable: !(bitmap & 2),
    writable: !(bitmap & 4),
    value: value
  };
};

var toString = {}.toString;

var classofRaw = function (it) {
  return toString.call(it).slice(8, -1);
};

var fails$4 = fails$6;
var classof = classofRaw;

var split = ''.split;

..........

.......
danr-za commented 3 years ago

Can you share a repro? I have a react publishable lib as well and don't have this issue.

ArielGueta commented 3 years ago

@danr-za create a new workspace, choose the npm option. Then, install nrwl/react, create a new publishable and buildable library, export a dummy hook, and build it.

ArielGueta commented 3 years ago

I now see that it happens only when using features like spread. It seems that it adds polyfills and I don't understand why. My target is "target": "ES2017",

ArielGueta commented 3 years ago

Ok, I figured it out. When creating npm workspace or a react library it doesn't create the .browserslistrc file for modern browsers. Therefore it uses IE11 and includes the polyfills.

I solved it by creating it manually and used the same config from here:

https://nx.dev/l/r/guides/browser-support

But I'm expecting it to be consistent and create it for me. Other developers maybe will not notice this, and include polyfills for nothing.

github-actions[bot] commented 2 years ago

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs. If we missed this issue please reply to keep it active. Thanks for being a part of the Nx community! 🙏

github-actions[bot] commented 1 year ago

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.