Open ThomasKientz opened 2 years ago
More details,
This issue is only happening with v5, not v4.
It is happening only for the modern build.
I can confirm I am also seeing this issue. One work around I found all though not great is to destructure after default import
import test from '@/test.js';
const { foo, ok } = test;
ok?.bar;
This does keep the optional chaining operator
As an example we ran into this access our vuex store state in a js file.
Another note as this was only an issue with the modern build and this is likely another bug the .browserlistrc
not IE 11
turns on modern build even if the cli specifies --no-module
when building.
This is also an issue in vue cli v4 when using the modern build flag @ThomasKientz can you confirm and if so will you update the ticket title?
Version
5.0.1
Reproduction link
https://github.com/ThomasKientz/vue-cli-repro/
Environment info
Steps to reproduce
From repo :
npm run serve // or npm run build --modern
open browser javascript console
note : I have forced modern build by adding "not ie 11" in browserslist.
What is expected?
Console to log
undefined
instead of throwing error.What is actually happening?
Optional chaining operator from default imports are not transpiled correctly with modern build.
test?.ok?.bar
is transpiled totest.ok.bar
,?
are stripped away leading to the error :Legacy build is fine.
May be related to https://github.com/webpack/webpack/issues/12960