question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

const, let and spread (not IE11 compatible)

See original GitHub issue

This library is expected to be consumed as is, however, without implicit include for babel-loader it will emit the original ES6 code to the final bundle, breaking old browsers.

Proposal:

PS: And is there any reason so spread result like return { ...memoryStatus };

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
developitcommented, Nov 15, 2019

In general, the compromise the community has arrived at is to publish both ES2017 and ES5 builds. Within the next few months, bundlers like Rollup and Webpack will begin to support for Node’s new “package exports” package.json annotations, which brings a community-standardized mechanism for shipping not just CJS and ESM, but ES-current and ES5:

{
  "main": "dist/es5-cjs.js",
  "module": "dist/es5-esm.js",
  "exports": {
    ".": {
      "default": "src/index.js"
    }
  }
}

In the meantime, if the source here is strictly ES2017 (no JSX, Babel extensions, class properties, etc), a small number of bundlers are configured to look for a "jsnext:main" package.json property, and will interpret this as a signal that the package contains ES2017 code, triggering transpilation when bundling for older browsers (and using the source as-is for modern browsers).

For now, I’d recommend shipping ESM and CJS using the "module" and "main" fields, unless the package is dramatically smaller when left as ES2017. Generally I’d recommend trying a solution like microbundle, which will generate these outputs automatically, and also now includes support for compiling to modern JS.

5reactions
addyosmanicommented, Nov 12, 2019

I had wanted to circle back on whether we needed to go for multi-build depending on community feedback. I would be happy to review a PR introducing two builds if someone would like to try out an approach.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IE 11 "Expected Identifier" error on spread operator found in ...
No issues with evergreen browsers. The error occurs at the first "." in the spread operator function, identified in the bundled js file...
Read more >
"Object spread" | Can I use... Support tables for HTML5, CSS3 ...
1 Notable partial support in IE11 includes (at least some) support for const , let , block-level function declaration, typed arrays, Map ,...
Read more >
let, var, and const - Go Make Things
Browser Compatibility #​​ let and const work in all modern browsers, and IE11 and up. They cannot be polyfilled. To push support back...
Read more >
A Simple Formula For When To Use Let, Const, and Var
By now, all major browsers and even IE11 support let and const . The var keyword declares a mutable reference to a value,...
Read more >
let - JavaScript - MDN Web Docs
Just like const the let does not create properties of the window object when declared globally (in the top-most scope).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found