Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Oddities when bundling for Node #984

Closed
webketje opened this issue Aug 5, 2022 · 2 comments
Closed

Oddities when bundling for Node #984

webketje opened this issue Aug 5, 2022 · 2 comments

Comments

@webketje
Copy link

webketje commented Aug 5, 2022

I've noticed following oddities when bundling for Node with the following command:

microbundle --target node --no-sourcemap -f cjs,esm --strict --types

When object spread operator is used ({ ...defaults, ...options }), in both the generated index.js and index.cjs (of a type: module package), those lines are replaced with a custom _extends function, which is added:

function _extends() {
  _extends = Object.assign || function (target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i];

      for (var key in source) {
        if (Object.prototype.hasOwnProperty.call(source, key)) {
          target[key] = source[key];
        }
      }
    }

    return target;
  };

  return _extends.apply(this, arguments);
}

Object spread is supported in Node since v8.3 and my package specifies engines.node >= 12 so this is "useless" extra code in the output. Temp fix is to directly use Object.assign in source code instead of obj spread.

Another oddity I noticed was that there was generated code referring to document but this shouldn't be the case for Node builds?

@rschristian
Copy link
Collaborator

"engines" in your package.json is totally ignored by Microbundle.

That being said, #954 bumped the Node target to 12 from 8. I believe targeting 8 effectively means 8.0.0, hence no spread. Hasn't been released yet I don't think.

@rschristian
Copy link
Collaborator

Can confirm, #954 does correct this. Closing this out as there's nothing actionable at the moment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants