ember.jsember-octane

Ember js build throws null coalescing error


I'm following the guide here to create getters in my component. However following the guide as it is gives me an error

Support for the experimental syntax 'nullishCoalescingOperator' isn't currently enabled

Searching through the guides, I couldn't find any documentation on how to enable this. I've tried this in my ember-cli-build.js file but that didn't work

'ember-cli-babel': {
  includePolyfill: true,
  nullishCoalescingOperator: true
}

and

'ember-cli-babel': {
  includePolyfill: true,
  nullishCoalescingOperator: 'enabled'
}

Update This works by manually installing the plug-in like the accepted answer shows, however even after upgrading ember-cli-babel to the latest version, it didn't work by default.


Solution

  • To add a plugin to the ember-cli build you should follow this format. For the nullish coalescing operator you would also need to npm install @babel/plugin-proposal-nullish-coalescing-operator.

    However as of January 10th 2020 the easiest way to get nullish coalescing is to ensure you have the latest version of ember-cli-babel v7.13.2 which contains the newest @babel/preset-env v7.8.3 which includes this plugin by default and then you won't need to make any changes to your build.

    You can see what version of @babel/preset-env you are running with the command npm ls @babel/preset-env. If it is before v7.8.3 then you might need to update it, I usually do this by updating all the transitive dependencies with:

    rm -r node_modules
    rm package-lock.json
    npm install