commerce icon indicating copy to clipboard operation
commerce copied to clipboard

Error: Component definition is missing display name

Open LucidNinja opened this issue 5 years ago • 3 comments

I'm receiving this error in Vercel, which exits the build in the Layout.tsx file on line 27:

const dynamicProps = {
  loading: () => <Loading />
};

const SignUpView = dynamic(() => import('@components/auth/SignUpView'), dynamicProps);

const ForgotPassword = dynamic(() => import('@components/auth/ForgotPassword'), dynamicProps);

const FeatureBar = dynamic(() => import('@components/common/FeatureBar'), dynamicProps);

Error: Component definition is missing display name react/display-name

It seems to be a linting error, but I've exhausted my options.

I've got the latest version of this repo, which includes NextJS 11.0.0 and Typescript 4.3.4.

LucidNinja avatar Jun 23 '21 11:06 LucidNinja

I have ignored this rule for now in .eslintrc, but it seems more like a hack:

{
  "extends": "next",
  "rules": {
    "react/display-name": "off"
  }
}

LucidNinja avatar Jun 23 '21 11:06 LucidNinja

I can reproduce this bug with the following steps.

In Vercel, create a new project using Next.js Commerce template.

  1. 1st commit will work fine.
  2. make minor changes to any HTML text, commit as 2nd commit and deploy
  3. deployment will fail with a few ESLint react/display-name error
  4. try to manual redeploy 1st commit now and it still gets deployed fine
  5. revert 2nd commit (as the 3rd commit) and deploy, the deployment will fail with react/display-name error again

image

wiiiimm avatar Dec 09 '21 16:12 wiiiimm

If you don't want to modify your esilnt, you can add a display name to the components. Typically this happens when wrapping a component with something like React.memo()

export const MyComponent: React.FC = () => {
  ...
}
MyComponent.displayName = 'MyComponent'

charkour avatar Dec 09 '21 16:12 charkour