react-hook-form-mui icon indicating copy to clipboard operation
react-hook-form-mui copied to clipboard

proposal-nullish-coalescing-operator compile error

Open wxsolo opened this issue 2 years ago • 7 comments

Duplicates

  • [X] I have searched the existing issues

Latest version

  • [X] I have tested the latest version

Current behavior 😯

when I add loaders plugins @babel/plugin-proposal-nullish-coalescing-operator

{
  "presets": [
    [
      "@babel/preset-env",
      {
        "useBuiltIns": "usage",
        "corejs": { "version": 3, "proposals": true }
      }
    ]
  ],
  "plugins": ["@babel/plugin-proposal-nullish-coalescing-operator"]
}

but has this error

Failed to compile.

./node_modules/react-hook-form-mui/dist/esm/index.js 36:18
Module parse failed: Unexpected token (36:18)
File was processed with these loaders:
 * ./node_modules/react-scripts/node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
|       return e.createElement(v, { ...a,
|         name: i,
>         value: s ?? "",
|         onChange: m,
|         onBlur: C,

Expected behavior 🤔

how to fix this "proposal-nullish-coalescing-operator" error

Steps to reproduce 🕹

Steps:

wxsolo avatar Jul 25 '22 13:07 wxsolo

@wxsolo this never been an issue before and not everyone seems to use that particular babel plugin. Pleases provide a PR which fixes the issue thanks

dohomi avatar Jul 28 '22 04:07 dohomi

I tried installing and using this package within my app that used create-react-app but ran into the same Failed to compile error as the above, so I'm unable to use the package. That nullish coalescing operator babel plugin is used by default in CRA (see here). Presumably this package's build needs to be compatible with that to ensure it can be used with apps created using create-react-app, though I'm not familiar with the details of this.

sjdemartini avatar Aug 24 '22 18:08 sjdemartini

Anyone figure out a solution/workaround to this? Have the same problem as @sjdemartini in that we use CRA and get this error thrown.

Gone down a rabbit hole of Github issues with browser targeting tweaks etc but nothing seems to resolve it.

jamiedruce avatar Oct 06 '22 14:10 jamiedruce

A repo which reproduce this issue would help. I am using this repo in 5+ production apps, all across NextJS, Storybook and Vite with React 17 and 18 and never seen it. Would be great if someone who faces this issue could wire up a reproduction and provide a PR or some insights about it. This library uses tsup under the hood to create the production bundles.

dohomi avatar Oct 07 '22 02:10 dohomi

FYI i'm looking to reproduce this in isolation. Interestingly I have made a basic codesandbox that works, but when ran locally, generates the error. So might be a local thing.

Will keep digging to see if I can find the root cause and why this package is the one that throws the error.

jamiedruce avatar Oct 07 '22 13:10 jamiedruce

OK, i've made some progress!

In my instance, i've isolated it to be related to using esbuild with react-scripts v4.0.3, in my testing, it can be resolved by removing esbuild and using default CRA's webpack

Upgrading react-scripts to v5.0.1 also worked, but I think only because v5 is not supported by craco which is used to swap in esbuild, causing it to default back to CRA default.

jamiedruce avatar Oct 07 '22 14:10 jamiedruce

good to hear, I havent used CRA for long time

dohomi avatar Oct 07 '22 14:10 dohomi