Bug with Amplify Hosting deployment

When attempting to deploy to amplify hosting with node version 16, pnpm, and Nextjs 13 with plasmic in codegen mode (default Amplify Hosting AMI, Amazon Linux 2), the build fails with the following error:

2022-12-27T19:18:12.092Z [INFO]: Done in 2s
2022-12-27T19:18:12.637Z [INFO]: Progress: resolved 6, reused 0, downloaded 6, added 6, done
2022-12-27T19:18:12.649Z [INFO]: # Executing command: pnpm exec next telemetry disable
2022-12-27T19:18:13.180Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2022-12-27T19:18:13.182Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2022-12-27T19:18:13.182Z [INFO]: Your preference has been saved to /codebuild/output/src678863488/src/<app name>/cache/config.json.
2022-12-27T19:18:13.183Z [INFO]: Status: Disabled
                                 You have opted-out of Next.js' anonymous telemetry program.
2022-12-27T19:18:13.183Z [INFO]: No data will be collected from your machine.
                                 Learn more: https://nextjs.org/telemetry
2022-12-27T19:18:13.192Z [INFO]: # Executing command: env | grep -e EMAIL_FROM -e XATA_API_KEY -e NEXTAUTH_URL -e NEXTAUTH_SECRET >> .env.production
2022-12-27T19:18:13.194Z [INFO]: # Completed phase: preBuild
2022-12-27T19:18:13.194Z [INFO]: # Starting phase: build
                                 # Executing command: pnpm run build
2022-12-27T19:18:13.590Z [INFO]: > <app name>@0.1.0 build /codebuild/output/src678863488/src/<app name>
                                 > next build
2022-12-27T19:18:13.836Z [INFO]: info  - Loaded env from /codebuild/output/src678863488/src/<app name>/.env.production
2022-12-27T19:18:13.948Z [INFO]: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2022-12-27T19:18:13.958Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2022-12-27T19:18:13.958Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2022-12-27T19:18:14.050Z [INFO]: info  - Skipping linting
2022-12-27T19:18:14.050Z [INFO]: info  - Checking validity of types...
2022-12-27T19:18:18.021Z [INFO]: info  - Creating an optimized production build...
TypeError: Cannot read properties of null (reading 'useMemo')
                                    at Object.exports.useMemo (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/react@18.2.0/node_modules/react/cjs/react.production.min.js:25:208)
                                    at exports.PlasmicRootProvider (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/@plasmicapp+react-web@0.2.135_biqbaboplfbrettd7655fr4n2y/node_modules/@plasmicapp/react-web/dist/react-web.cjs.production.min.js:1:25352)
                                    at Wc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at $c (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
2022-12-27T19:18:43.581Z [INFO]: info  - Generating static pages (3/5)
2022-12-27T19:18:43.581Z [WARNING]: Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
                                    TypeError: Cannot read properties of null (reading 'useMemo')
                                    at Object.exports.useMemo (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/react@18.2.0/node_modules/react/cjs/react.production.min.js:25:208)
                                    at exports.PlasmicRootProvider (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/@plasmicapp+react-web@0.2.135_biqbaboplfbrettd7655fr4n2y/node_modules/@plasmicapp/react-web/dist/react-web.cjs.production.min.js:1:25352)
                                    at Wc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at $c (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
2022-12-27T19:18:43.602Z [WARNING]: Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
                                    TypeError: Cannot read properties of null (reading 'useMemo')
                                    at Object.exports.useMemo (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/react@18.2.0/node_modules/react/cjs/react.production.min.js:25:208)
                                    at exports.PlasmicRootProvider (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/@plasmicapp+react-web@0.2.135_biqbaboplfbrettd7655fr4n2y/node_modules/@plasmicapp/react-web/dist/react-web.cjs.production.min.js:1:25352)
                                    at Wc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at Zc (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:481)
                                    at Z (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
                                    at $c (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
2022-12-27T19:18:43.602Z [INFO]: info  - Generating static pages (5/5)
2022-12-27T19:18:43.606Z [WARNING]: > Build error occurred
                                    Error: Export encountered errors on following paths:
                                    /
                                    /_error: /404
                                    /_error: /500
                                    /auth
                                    /plasmic-host
                                    at /codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/export/index.js:409:19
                                    at runMicrotasks (<anonymous>)
                                    at processTicksAndRejections (node:internal/process/task_queues:96:5)
                                    at async Span.traceAsyncFn (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/trace/trace.js:79:20)
                                    at async /codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/build/index.js:1345:21
                                    at async Span.traceAsyncFn (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/trace/trace.js:79:20)
                                    at async /codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/build/index.js:1205:17
                                    at async Span.traceAsyncFn (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/trace/trace.js:79:20)
                                    at async Object.build [as default] (/codebuild/output/src678863488/src/<app name>/node_modules/.pnpm/next@13.1.1_biqbaboplfbrettd7655fr4n2y/node_modules/next/dist/build/index.js:66:29)
2022-12-27T19:18:43.642Z [INFO]: ELIFECYCLE  Command failed with exit code 1.
2022-12-27T19:18:43.648Z [ERROR]: !!! Build failed
2022-12-27T19:18:43.649Z [INFO]: Please check the supported SSR features to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/ssr-Amplify-support.html#supported-unsupported-features. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
2022-12-27T19:18:43.649Z [ERROR]: !!! Non-Zero Exit Code detected
2022-12-27T19:18:43.649Z [INFO]: # Starting environment caching...
2022-12-27T19:18:43.649Z [INFO]: # Environment caching completed
Terminating logging...

amplify.yml

version: 1
frontend:
  phases:
    preBuild:
      commands:
        - npm install -g pnpm
        - pnpm install
        - pnpm exec next telemetry disable
        - env | grep -e EMAIL_FROM -e XATA_API_KEY -e NEXTAUTH_URL -e NEXTAUTH_SECRET >> .env.production
    build:
      commands:
        - pnpm run build
  artifacts:
    baseDirectory: .next
    files:
      - '**/*'
  cache:
    paths:
      - node_modules/**/*

Hi, I suspect the issue has to do with pnpm.

Can you try deploying a brand new next year has code base created using create-plasmic-app? Do you see the same issue?