privatenumber / esbuild-loader

💠 Speed up your Webpack with esbuild ⚡️
MIT License
3.58k stars 106 forks source link

Optional Chaining not working #341

Closed sunyeongchoi closed 1 year ago

sunyeongchoi commented 1 year ago

Problem

I changed from babel to esbuild-loader.

However, after changing to esbuild-loader, optional chaining does not work properly.

The document states that the optional chaining function is available when using ES2020.

image

My webpack configuration is as follows, but it doesn't work properly.

{
        enforce: 'pre',
        test: /\.js$/,
        exclude: [/node_modules/, /build/],
        loader: 'esbuild-loader',
      },
      {
        test: /\.tsx?$/,
        loader: 'esbuild-loader',
        options: {
          loader: 'tsx',
          target: 'es2020',
        },
      },

The following error occurs:

ERROR in ./src/features/resources/catalog/UserCatalogCreatePage.tsx 9:63
Module parse failed: Unexpected token (9:63)
File was processed with these loaders:
 * ./node_modules/esbuild-loader/dist/index.js
You may need an additional loader to handle the result of these loaders.
| const UserCatalogCreatePage = ({ match }) => {
|   const breadcrumbs = useGetCreateBreadCrumbs(void 0);
>   const createItem = useMemo(() => getCreateItemByString(match?.params?.createitem), [match]);
|   return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Helmet, { title: createItem?.name || "" }), /* @__PURE__ */ React.createElement("div", { className: "container" }, /* @__PURE__ */ React.createElement("div", { className: "top_title" }, /* @__PURE__ */ React.createElement(Breadcrumbs, { breadcrumbs })), /* @__PURE__ */ React.createElement(CreateContentFactory, { match })));
| };

Expected behavior

Optional chaining should work properly.

Minimal reproduction URL

no

Version

v2.18.0

Node.js version

v16.20.2

Package manager

yarn

Operating system

Linux

Contributions

privatenumber commented 1 year ago

Can you provide a reproduction? Happy to re-open once provided.