question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Storybook 6 with Vue.js doesn't support optional chaining

See original GitHub issue

Describe the bug Storybook 6 with Vue.js doesn’t support optional chaining with the zero config TypeScript.

To Reproduce Steps to reproduce the behavior:

  1. Use the https://github.com/storybookjs/storybook/tree/next/examples/vue-cli example
  2. Add some code which uses optional chaining in Button.vue
const test: string | undefined = "";

if (test?.toString())
{
  console.log(test);
}
  1. 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:closed
  • Created 3 years ago
  • Comments:12 (2 by maintainers)

github_iconTop GitHub Comments

16reactions
DavidRouyercommented, Jul 13, 2020

I’ve found the culprit, it looks like the "target": "esnext" doesn’t support optional chaining anymore 😕 You have to use "target": "ES2018" for example

5reactions
F0rsakencommented, Mar 11, 2021

Actually, I don’t know if changing the target property is the solution. Let’s say I want to keep it as esnext or lower for browser compatybility. What should I do then?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Storybook 6 with Vue.js doesn't support optional chaining ...
Describe the bug Storybook 6 with Vue.js doesn't support optional chaining with the zero config TypeScript. To Reproduce Steps to reproduce the behavior:....
Read more >
Error while importing a module with optional chaining
The Vue forums are in denial about this problem, claiming Vue 3 supports optional chaining. Apparently not, however, in node modules.
Read more >
Error while importing a module with optional chaining-Vue.js
The Vue forums are in denial about this problem, claiming Vue 3 supports optional chaining. Apparently not, however, in node modules. A post...
Read more >
Optional Chaining for JavaScript with Babel 7 and Webpack 4
npm install --save-dev babel-loader @babel/core @babel/plugin-proposal-optional-chaining · module: { rules: [ { test: /\.js$/, exclude: /node_modules/, loader: " ...
Read more >
babel/plugin-transform-typescript
Note that although the TypeScript compiler tsc actively supports certain JavaScript proposals such as optional chaining ( ?. ), nullish coalescing ( ??...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found