In my Vue-CLI project, when I tried using the ??
operator, I got this error:
Syntax Error: SyntaxError: /Users/stevebennett/odev/freelancing/v-map/src/components/Map.vue: >Support for the experimental syntax 'nullishCoalescingOperator' isn't currently enabled (30:29):
...
Add @babel/plugin-proposal-nullish-coalescing-operator (https://git.io/vb4Se) to the 'plugins' section of your Babel config to enable transformation.
I installed @babel/plugin-syntax-nullish-coalescing-operator (its name seems to have changed), added it to my babel.config.js:
module.exports = {
presets: ['@vue/app'],
plugins: ['@babel/plugin-syntax-nullish-coalescing-operator'],
};
Now the error message seems to have gone backwards, no reference to the operator name at all:
Module parse failed: Unexpected token (39:35)
You may need an appropriate loader to handle this file type.
| case 8:
| points = _context.sent;
console.log(sheetID ?? 37);
What am I doing wrong?
A default Vue CLI project uses @vue/babel-preset-app, which uses @babel/preset-env and the browserslist config to determine the Polyfills needed for your project.
Using a PluginIf the plugin is on npm, you can pass in the name of the plugin and Babel will check that it's installed in node_modules . This is added to the plugins config option, which takes an array. You can also specify an relative/absolute path to your plugin.
vue. config. js configures Vue. These are two different things. Babel transforms newer Javascript into old Javascript so that older browsers (notably IE11) can understand it.
For me, the @babel/plugin-syntax-nullish-coalescing-operator
plugin would not work, which is the one you are using.
I had to use the @babel/plugin-proposal-nullish-coalescing-operator
plugin which is the one that the error message suggests you use.
Additionally, I noticed this on the page for the @babel/plugin-syntax-nullish-coalescing-operator
plugin:
I can't say for sure if this will fix your problem, but it certainly fixed mine
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With