Closed matthewsuan closed 3 years ago
optional chaining support was added in node_V14 https://node.green/#ES2020-features-optional-chaining-operator-----
Ya it was an issue with @vue/cli-plugin-babel/preset.
All the default browser targets in the said preset now supports optional chaining.
So Babel did not compile with optional chaining enabled since target browsers already support it.
@matthewsuan I updated all dependencies and still have this issue, is there any config (babel ?) that I need to modify ? Any help appreciated 😄
My configs:
// babel.config.js
module.exports = {
presets: [
'@vue/app'
]
}
// package.json
"devDependencies": {
...
"@babel/core": "^7.13.1",
"@cypress/webpack-preprocessor": "^5.6.0",
"@vue/cli-plugin-babel": "^4.5.11",
"@vue/cli-plugin-e2e-cypress": "^4.5.11",
"@vue/cli-service": "^4.5.11"
...
}
// tests/e2e/plugins/index.js
const webpack = require('@cypress/webpack-preprocessor')
module.exports = (on, config) => {
on('file:preprocessor', webpack({
webpackOptions: require('@vue/cli-service/webpack.config'),
watchOptions: {}
}))
return Object.assign({}, config, {
fixturesFolder: 'tests/e2e/fixtures',
integrationFolder: 'tests/e2e/specs',
screenshotsFolder: 'tests/e2e/screenshots',
videosFolder: 'tests/e2e/videos',
supportFile: 'tests/e2e/support/index.js'
})
}
And error:
Module parse failed: Unexpected token (15:15)
File was processed with these loaders:
* ./node_modules/cache-loader/dist/cjs.js
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| const computeKey = key => {
| const ite = JSON.parse(localStorage.getItem('ite'));
> return ite?.authenticated ? `${key}-${ite.session?.user?.id}` : key;
| };
|
@mgibas this is my babel config.
module.exports = {
presets: [
[
"@vue/cli-plugin-babel/preset",
{
targets: {
chrome: "87.0.0",
edge: "87.0.0",
firefox: "84.0.0",
ios: "13.3.0",
safari: "13.1.0"
}
}
]
]
};
The idea was to downgrade atleast one of the targets to a version that doesn't support optional chaining to force babel to include optional chaining plugin.
@matthewsuan hmmm, weirdly this doesn't work in my case - even adding IE11 doesn't force the transpilation :( If you have any other ideas or things I can check it would be great. Thanks for a quick response though 👍🏼
Edit: Oh, I forgot to mention that im hitting these issues during cypress tests run
@mgibas Did you manage to solve it?
Yes - I’ll try to find what was that exactly cause all I remember now is that it was my fault :)
Ok found it, super minor and confusing thing:
make sure that you run your tests with NODE_ENV=production
- without it Babel will not kick in (which makes total sense).
I just added that to my .env.test
file.
Version
4.5.11
Environment info
Steps to reproduce
vue-cli-service build
What is expected?
build to succeed
What is actually happening?
build failed
error in ./src/components/TheNavbar.vue?vue&type=script&lang=js&
Module parse failed: Unexpected token (86:31) File was processed with these loaders: