-
Notifications
You must be signed in to change notification settings - Fork 214
Optional chaining doesn't work out of the box #1641
Comments
Adding the const react = require("@neutrinojs/react");
const babelMerge = require("babel-merge");
module.exports = {
options: {
root: __dirname,
},
use: [
react(),
neutrino =>
neutrino.config.module
.rule("compile")
.use("babel")
.tap(options => babelMerge(options, {
plugins: ["@babel/plugin-proposal-optional-chaining"]
}))
],
}; |
This is actually because Neutrino's default browser targets are all able to do optional chaining natively (https://github.com/neutrinojs/neutrino/blob/master/packages/web/index.js#L121) That means the optional chaining never gets transpiled by Babel (which is good; the targets don't need it to be). But sadly, Webpack 4 fails to parse that syntax during the bundling stage. Apparently it's fixed in Webpack 5. If you want to enable optional chaining transpilation without adding it explicitly, you can target a browser which needs the transpilation: use: [
react({
targets: { browsers: [
// the default targets:
'last 2 Chrome versions',
'last 2 Firefox versions',
'last 2 Edge versions',
'last 2 Opera versions',
'last 2 Safari versions',
'last 2 iOS versions',
// a target which needs optional chaining transpilation:
'ie 11',
] }
}),
], But of course that's also just a workaround. Further reading:
|
[UTCORE-121]
Bug
The text was updated successfully, but these errors were encountered: