Webpack cant compile ts 3.7 (Optional Chaining, Nullish Coalescing)

Edgaras Karka picture Edgaras Karka · Nov 12, 2019 · Viewed 14.1k times · Source

I try to use typescript 3.7 features like Optional Chaining, Nullish Coalescing. But webpack gives me an error while transpaling.

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);
``

Answer

Edgaras Karka picture Edgaras Karka · Nov 13, 2019

I changed target: esnext to es2018 in tsconfig.json file. Now it works.

Webpack issue for reference : https://github.com/webpack/webpack/issues/10227