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.

Nullish coalescing / optional chaining support without IE11 in targets

See original GitHub issue

Currently production builds wihout IE11 in targets will fail if Nullish coalescing / optional chaining used in project codebase.

Issue from: https://github.com/terser/terser/issues/567 Related issue: https://github.com/ember-cli/ember-cli-uglify/issues/49

Error will looks like:

ERROR Summary:

  - broccoliBuilderErrorStack: SyntaxError: Unexpected token: punc (.)
    at ee (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:19541)
    at c (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:28244)
    at l (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:28335)
    at f (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:28388)
    at G (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:42202)
    at ge (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:48272)
    at C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:49152
    at be (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:49167)
    at ze (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:50421)
    at qe (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\terser\dist\bundle.min.js:1:50653)
  - code: [undefined]
  - codeFrame: Unexpected token: punc (.)
  - errorMessage: Unexpected token: punc (.)
        at UglifyWriter
-~- created here: -~-
    at UglifyWriter.Plugin (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\broccoli-plugin\index.js:7:31)
    at new UglifyWriter (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\broccoli-uglify-sourcemap\index.js:38:10)
    at UglifyWriter (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\broccoli-uglify-sourcemap\index.js:33:12)
    at Class.postprocessTree (C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\ember-cli-uglify\index.js:54:50)
    at C:\Users\lifeart\Documents\repos\brn\frontend\node_modules\ember-cli\lib\utilities\addon-process-tree.js:6:25
    at Array.reduce (<anonymous>:null:null)

Discord thread: https://discord.com/channels/480462759797063690/486548111221719040/737966824775221258

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:10
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

6reactions
pichflcommented, Aug 12, 2020

Another potential fix: Explicitly include the babel plugins for those two features into your ember-cli-build.js like this:

module.exports = function (defaults) {
  const app = new EmberApp(defaults, {
    babel: {
      include: ['proposal-nullish-coalescing-operator', 'proposal-optional-chaining'], // Remove once terser supports these
      plugins: [require.resolve('ember-auto-import/babel-plugin')],
    },
  });

  return app.toTree();
};
4reactions
boris-petrovcommented, Jul 29, 2020

As a workaround, one could use targets that are for browsers without native support for those two features (so they are transpiled by babel and terser won’t blow up). I, personally, use these:

'chrome >= 82',
'edge >= 18',
'firefox >= 76',
'safari >= 13',

And that works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Does the nullish coalescing operator (??) in TypeScript have ...
As for now, yes, nullish coalescing will be transpiled, along with all the other syntax that isn't yet supported by your target ES...
Read more >
Nullish coalescing operator (??) - JavaScript - MDN Web Docs
The nullish coalescing operator treats undefined and null as specific values. So does the optional chaining operator ( ?. ), which is useful...
Read more >
Optional chaining and nullish coalescing in TypeScript
Use two features of TypeScript 3.7: optional chaining and nullish coalescing, to write simple code without never-ending conditionals.
Read more >
soda on Twitter: "Reminder to all developers that still need to ...
The default queries no longer target IE11 anymore. Quote Tweet ... which depends on acorn 6, which never supports optional chaining and nullish...
Read more >
vue/cli - Awesome JS
The default browserslist query no longer includes IE 11 as a target. ... so that optional chaining and nullish coalescing syntaxes won't cause...
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