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.

Could not use `optional chaining` in nuxt.config.ts

See original GitHub issue

Describe the bug Using optional chaining in nuxt.config.ts causes run-time error.

 ERROR  Unexpected token . 

  const hello = fuga?.foo.bar;
  ^

  SyntaxError: Unexpected token .

To Reproduce See CodeSandbox

https://codesandbox.io/embed/nuxtnuxtjs-typescript-q064y?fontsize=14&hidenavigation=1&theme=dark

Expected behavior No error happens

Additional context To avoid this error, change target property’s value of tsconfig.json into es2018 from esnext. https://github.com/TypeStrong/ts-node/issues/903#issuecomment-551265568

But the configuration displayed in the official document says that targe value is esnext. https://typescript.nuxtjs.org/guide/setup.html#configuration

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
kevinmarreccommented, Dec 11, 2019

@azawakh Wow thanks, it seems that babel plugins are not needed at all then, we can let TypeScript handles the transpilation of the features by specifying.

Only esnext seems buggy, es5 / es2018 / es2019 / es2020 work well.

I’m gonna remove Babel plugins and tell people to update their TypeScript configuration file in release so it works out of the box for build & runtime ouf of the box !

1reaction
kevinmarreccommented, Dec 11, 2019

Closed by https://github.com/nuxt/typescript/commit/826234b5ff24a90e771d10b1029d1adabd8de6fb

Babel plugins will be removed (useless if using es2018 target) in next release later this day.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Nuxt 2 optional chaining is not working for template as well as ...
I had vue-template-babel-compiler installed to support optional chaining for the templates but after doing a fresh npm install, ...
Read more >
Setup - Nuxt TypeScript
Notice that ES2018 target is needed to be able to use Optional Chaining and Nullish Coalescing, as ESNext target doesn't seem to support...
Read more >
nuxt-ts-optional-chaining - CodeSandbox
CodeSandbox is an online editor tailored for web applications.
Read more >
@nuxt/typescript-build - Awesome JS
If using Nuxt 2.15 (with jiti ), Node.js 14 is required if you're using or planning to use Optional chaining and Nullish coalescing....
Read more >
Can't set up @babel/plugin-proposal-optional-chaining
A couple months ago, when Vue CLI 3 was still in beta, I experimented on a new project with optional chaining, using @babel/plugin-proposal- ......
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