Could not use `optional chaining` in nuxt.config.ts
See original GitHub issueDescribe 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:
- Created 4 years ago
- Reactions:1
- Comments:10 (3 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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 !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.