首页 > 解决方案 > Webpack 无法编译 ts 3.7 (Optional Chaining, Nullish Coalescing)

问题描述

我尝试使用typescript 3.7可选链接、空值合并等功能。但是webpack在转换时给了我一个错误。

app: Module parse failed: Unexpected token (50:40)
app: File was processed with these loaders:
app:  * ../../../node_modules/ts-loader/index.js
app: You may need an additional loader to handle the result of these loaders.
app: | export const Layout = (props) => {
app: |     const regionsResults = useQuery(regionsQuery, { fetchPolicy: 'cache-first' });
app: >     const regions = regionsResults.data?.regions ?? [];
app: |     const userItem = useQuery(usersProfileQuery, { fetchPolicy: 'cache-first' });
app: |     const handleOnClick = (selected) => props.history.push(selected.key);
``

标签: typescriptwebpackts-loader

解决方案


我将目标:更改esnextes2018文件中tsconfig.json。现在它起作用了。

Webpack 问题供参考:https ://github.com/webpack/webpack/issues/10227


推荐阅读