Storybook 6 with Vue.js doesn't support optional chaining
See original GitHub issueDescribe the bug Storybook 6 with Vue.js doesn’t support optional chaining with the zero config TypeScript.
To Reproduce Steps to reproduce the behavior:
- Use the https://github.com/storybookjs/storybook/tree/next/examples/vue-cli example
- Add some code which uses optional chaining in
Button.vue
const test: string | undefined = "";
if (test?.toString())
{
console.log(test);
}
- See the error in console
ERROR in ./src/button/Button.vue?vue&type=script&lang=ts& (./node_modules/vue-docgen-loader/lib??ref--14!./node_modules/ts-loader??ref--4-0!./node_modules/vue-loader/lib??vue-loader-options!./src/button/Button.vue?vue&type=script&lang=ts&) 6:9
Module parse failed: Unexpected token (6:9)
File was processed with these loaders:
* ./node_modules/vue-docgen-loader/lib/index.js
* ./node_modules/vue-docgen-loader/lib/index.js
* ./node_modules/ts-loader/index.js
* ./node_modules/vue-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| import { Prop } from 'vue-property-decorator';
| const test = "";
> if (test?.toString()) {
| console.log(test);
| }
Expected behavior The code should not throw an error.
Screenshots If applicable, add screenshots to help explain your problem.
Code snippets If applicable, add code samples to help explain your problem.
System:
Please paste the results of npx -p @storybook/cli@next sb info
here.
Additional context The vue-cli example doesn’t not work out of the box, some dependencies are missing.
You can see the reproduction here: https://github.com/DavidRouyer/storybook-vue-cli-example
I’ve added the missing dependencies in https://github.com/DavidRouyer/storybook-vue-cli-example/commit/77a14b816c3dc21c70a8c9e53cf58dcaa6a99103
I’ve added the code which breaks the build in https://github.com/DavidRouyer/storybook-vue-cli-example/commit/38f7ccc93e4cc3c91a2b3af3bdfe6c623327d540
Issue Analytics
- State:
- Created 3 years ago
- Comments:12 (2 by maintainers)
Top GitHub Comments
I’ve found the culprit, it looks like the
"target": "esnext"
doesn’t support optional chaining anymore 😕 You have to use"target": "ES2018"
for exampleActually, I don’t know if changing the
target
property is the solution. Let’s say I want to keep it asesnext
or lower for browser compatybility. What should I do then?