Unable to use LexicalRichText component from @yext/react-components

I’m in the process of converting a client’s “Classic” Pages site to React and when attempting to render a Rich Text v2 field using the LexicalRichText component from @yext/react-components (as instructed in the documentation, immediately on saving the component that includes the LexicalRichText component implementation, the site refuses to compile and the following error appears in the terminal:

❯ npm run dev

> blink-location-pages@0.0.1 dev
> pages dev

(node:82021) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
This is a beta version of the Yext Command Line Interface

Settings from your current credential [blink-location-pages-3258070] are:
Name:            blink-location-pages-3258070
Universe:        sandbox
Account ID:      3258070
Account Name:    blink-location-pages

> pages generate templates 
(node:82057) ExperimentalWarning: The Node.js specifier resolution flag is experimental. It could change or be removed at any time.
(Use `node --trace-warnings ...` to show where the warning was created)
(node:82057) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
12:25:52 PM [vite] Error when evaluating SSR module /src/components/common/Footer.tsx: failed to import "@yext/react-components"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:52 PM [vite] Error when evaluating SSR module /src/layouts/main.tsx: failed to import "/src/components/common/Footer.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:52 PM [vite] Error when evaluating SSR module /src/layouts/search/template.tsx: failed to import "/src/layouts/main.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:52 PM [vite] Error when evaluating SSR module /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/src/templates/search.tsx?update=1702923949541: failed to import "/src/layouts/search/template.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

Node.js v18.15.0
> yext pages generate-test-data
This is a beta version of the Yext Command Line Interface

WARNING: unexpected keys in site config: "siteStream.fields.[10]"
Generated 0 files for stream "directory-state"
Generated 1 files for stream "search-page"
Generated 1 files for stream "directory-root"
Generated 10 files for stream "directory-city"
Generated 10 files for stream "location-stream"
Generated 2 files for static features
listening on :5173
(node:82021) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
12:25:57 PM [vite] Error when evaluating SSR module /src/components/common/Footer.tsx: failed to import "@yext/react-components"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:57 PM [vite] Error when evaluating SSR module /src/layouts/main.tsx: failed to import "/src/components/common/Footer.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:57 PM [vite] Error when evaluating SSR module /src/layouts/search/template.tsx: failed to import "/src/layouts/main.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

12:25:57 PM [vite] Error when evaluating SSR module /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/src/templates/search.tsx?update=1702923955187: failed to import "/src/layouts/search/template.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

SyntaxError: Unexpected token 'export'
12:25:57 PM [vite] Error when evaluating SSR module /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/src/templates/search.tsx?update=1702923957652: failed to import "/src/layouts/search/template.tsx"
|- /Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/react-components/lib/esm/index.js:1
export { Address } from "./components/address";
^^^^^^

SyntaxError: Unexpected token 'export'
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1176:20)
    at Module._compile (node:internal/modules/cjs/loader:1218:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Module._load (node:internal/modules/cjs/loader:958:12)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
    at ModuleJob.run (node:internal/modules/esm/module_job:194:25)

SyntaxError: Unexpected token 'export'

In the above error, export { Address } from "./components/address"; is referring to an export in@yext/react-components (/node_modules/@yext/react-components/lib/esm/components/address/index.js) npm module rather than something in the project’s code.

I’m using the Pages React Starter Consulting template. My package.json includes "type": "module". My tsconfig.json is unchanged from the template.

The usage of the LexicalRichText component is as follows:

import { Link } from '@yext/sites-components';
import { LexicalRichText } from '@yext/react-components';
import { type C_FooterLinkSections, type RtfV2 } from 'src/types/entities';
import { FooterLinkSection } from './FooterLinksSection';
import {
  Facebook,
  Instagram,
  Twitter,
  TikTok,
} from 'src/assets/svgs/SocialIcons';
import { Logo } from 'src/assets/svgs/LogoIcons';

interface FooterProps {
  copyrightMessage?: string;
  twitter?: string;
  facebook?: string;
  instagram?: string;
  tikTok?: string;
  androidAppUrl?: string;
  iosAppUrl?: string;
  footerLinkSections?: C_FooterLinkSections[];
  notificationBannerTerms?: RtfV2;
  notificationBannerText?: RtfV2;
}

const Footer = (props: FooterProps) => {
  const {
    twitter,
    facebook,
    instagram,
    tikTok,
    copyrightMessage,
    notificationBannerTerms,
    footerLinkSections,
  } = props;

  const socialLinks = [
    { link: facebook, label: Facebook },
    { link: tikTok, label: TikTok },
    { link: instagram, label: Instagram },
    { link: twitter, label: Twitter },
  ].filter((link) => link.link);

  return (
    <footer className="flex justify-center pt-0 md:pt-8 md:m-4">
      <div className="flex flex-col justify-center gap-10">
        <div className="flex flex-row justify-evenly h-full gap-20 flex-grow">
          <div className="flex flex-row md:flex-col justify-start mb-8 mt-5 md:my-0 md:max-w-[16.25rem]">
            <Logo className="max-w-full max-h-full w-[5.1875rem] md:h-[3.1875rem] md:w-[8.8123rem]" />
            <div className="flex flex-row items-end gap-4">
              {socialLinks.map((socialLink, i) =>
                socialLink.link ?
                  <Link
                    className="inline-block w-7 h-7 md:mr-4 md:last:mr-0"
                    key={i}
                    href={socialLink.link}
                  >
                    <socialLink.label className="inline-block w-7 h-7 md:mr-4 md:last:mr-0" />
                  </Link>
                : null,
              )}
            </div>
          </div>
          <div className="hidden md:flex flex-col">
            <FooterLinkSection footerLinkSections={footerLinkSections || []} />
          </div>
        </div>
        <div className="flex flex-row justify-start w-full h-full">
          <div className="text-sm/[1.07rem] text-left text-brand-gray-11">
            {copyrightMessage}
          </div>
        </div>
        <div className="flex flex-row justify-start w-full h-full">
          <div className="terms">
            {notificationBannerTerms && (
              <LexicalRichText
                serializedAST={JSON.stringify(notificationBannerTerms.json)}
              />
            )}
          </div>
        </div>
      </div>
    </footer>
  );
};

export { Footer };

There is an issue with react-components and the latest version of PagesJS/Vite. We are currently in the process of moving over components from @yext/react-components to @yext/pages-components which includes a fix for this issue.

1 Like

Hi Duval, do we have an ETA for resolving this issue? Thanks!

I just released @yext/pages-components-rc.0. Swap to this package for LexicalRichText and you should be good!

1 Like

We’ll also work on updating the documentation to reflect this newer library.

Thank you so much, Duval - I sincerely appreciate this!

Thanks so much, Duval and Miriam!

So I finally got around to implementing LexicalRichText from @yext/pages-components (v1.0.0-rc.0) and now I’m getting a new error that appears to be related to the LexicalRichText component as implemented in @yext/pages-components:

Error 500

500 TypeError: i.isEmpty is not a function
    at vg.setEditorState (file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages-components/dist/index-i0mhhNq7.js:13256:13)
    at O (file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages-components/dist/index-i0mhhNq7.js:13519:15)
    at file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages-components/dist/index-i0mhhNq7.js:13484:11
    at Object.useMemo (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:1582:19)
    at Object.useMemo (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react/cjs/react.development.js:1532:21)
    at T (file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages-components/dist/index-i0mhhNq7.js:13463:17)
    at processChild (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:3353:14)
    at resolve (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:3270:5)
    at ReactDOMServerRenderer.render (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:3753:22)
    at ReactDOMServerRenderer.read (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:3690:29)
    at Proxy.renderToString (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/react-dom/cjs/react-dom-server.node.development.js:4298:27)
    at Module.render (/Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages/dist/common/src/template/internal/_server.js:5:35)
    at getServerHtml (file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages/dist/dev/server/middleware/sendAppHTML.js:20:45)
    at sendAppHTML (file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages/dist/dev/server/middleware/sendAppHTML.js:34:11)
    at async file:///Users/ryan/Coding/crometrics/blink-location-pages/new/blink-location-pages/node_modules/@yext/pages/dist/dev/server/middleware/serverRenderSlugRoute.js:64:5

Here is the implementation I tested it on:

import { CloseIcon } from 'src/assets/svgs/CloseIcon';
import { LexicalRichText } from '@yext/pages-components';
import './styles/NotificationBanner.css';
import type { NotificationBanner } from 'src/types/entities';

/* 
  type NotificationBanner (imported above) is typed as:

    export interface RichTextField {
      readonly json: string;
    }

    export interface NotificationBanner {
      readonly backgroundHexCode: string;
      readonly textHexCode: string;
      readonly bannerText: RichTextField;
    }
*/


interface NotificationBannerProps {
  notificationBanner?: NotificationBanner;
}

const NotificationBanner = ({
  notificationBanner,
}: NotificationBannerProps) => (
  <div className="Notification-banner">
    <div className="Notification-banner__Container">
      <a
        className="Notification-banner__Link"
        href="https://locations.blinkfitness.com/index.html"
      >
        <div className="Notification-banner__Content">
          <div className="Notification-banner__Bubbles">
            <div className="Notification-banner__Bubble--orange"></div>
            <div className="Notification-banner__Bubble--blue"></div>
          </div>
          <div className="Notification-banner__Copy">
            {notificationBanner && (
              <LexicalRichText
                serializedAST={notificationBanner.bannerText.json}
              />
            )}

            {/* <div>NOTIFICATION BANNER PLACEHOLDER COPY</div> */}
          </div>
        </div>
      </a>
      <button aria-label="Close" className="Notification-banner__Close">
        <CloseIcon className="w-[0.7875rem] h-[0.7875rem] shrink-0" />
      </button>
    </div>
  </div>
);

export { NotificationBanner };

I’m guessing that it’s because you didn’t JSON.stringify the json field you’re using.

Yep, you are right. I forgot to stringify the JSON when I attempted to reimplement it. :man_facepalming:

Thanks much for the help!