Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build error on Vercel deployments after upgrading to 13.4 #49261

Closed
1 task done
laubonghaudoi opened this issue May 5, 2023 · 16 comments · Fixed by #49274
Closed
1 task done

Build error on Vercel deployments after upgrading to 13.4 #49261

laubonghaudoi opened this issue May 5, 2023 · 16 comments · Fixed by #49274
Labels
bug Issue was opened via the bug report template.

Comments

@laubonghaudoi
Copy link

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: darwin
      Arch: x64
      Version: Darwin Kernel Version 22.4.0: Mon Mar  6 21:00:17 PST 2023; root:xnu-8796.101.5~3/RELEASE_X86_64
    Binaries:
      Node: 16.13.2
      npm: 9.6.4
      Yarn: 3.4.1
      pnpm: 7.21.0
    Relevant packages:
      next: 13.4.0
      eslint-config-next: 13.4.0
      react: 18.2.0
      react-dom: 18.2.0

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue

none

To Reproduce

Upgrade next from ^13.3.4 tp ^13.4.0. The project is using pages/, not using app/dir nor turbopack.

Describe the Bug

I just updated the nextJS version from 13.3 to 13.4 without change anything in my codebase. The local build is successful without any errors, but when deployed on Vercel, I got hundreds of lines of error like

Error occurred prerendering page "/en/post/100". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useEffect')
    at exports.useEffect (/vercel/path0/node_modules/react/cjs/react.production.min.js:24:292)
    at Analytics (file:///vercel/path0/node_modules/@vercel/analytics/dist/react/index.js:132:3)
    at Ge (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:114:273)
    at Z (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:120:91)
    at He (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:123:155)
    at Je (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:122:100)
    at Z (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:120:222)
    at Ge (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:119:95)
    at Z (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:120:91)
    at Ge (/vercel/path0/node_modules/next/dist/compiled/react-dom/cjs/react-dom-server.browser.production.min.js:115:9)

I speculate that this is caused by my components not being specified as client components. But I am not using the app/ directory, I am only using the /pages. Does that mean I need to specify client components even if I am using /pages? I tried adding 'use client' to the top of my component files and the error still persists.

The local builds are successful without any errors, this only happens on Vercel deployments.

Expected Behavior

Build should be successful with no error.

Which browser are you using? (if relevant)

irrelevant

How are you deploying your application? (if relevant)

Vercel

@laubonghaudoi laubonghaudoi added the bug Issue was opened via the bug report template. label May 5, 2023
@lucasishuman
Copy link

FYI - related discussion - #49251

@kgilliam125
Copy link

@laubonghaudoi Ran into the same issue you're describing with a previously working build. This is silly, but did you make sure to yarn/npm install again after you reverted the version in your package.json?

My build seems to be running again on Next 13.3.4 but is broken in 13.4

@benjwexler
Copy link

I was facing a similar issue after trying to upgrade locally for a Next app using a custom server. Adding the following to next.config.js seems to have fixed the issue:

experimental: {
  appDir: false,
},

@joachimjusth
Copy link

I had also the same issue when I did the migration to Next 13.4.

I added the flag given by @benjwexler , and now it deploy without any issue.

I was facing a similar issue after trying to upgrade locally for a Next app using a custom server. Adding the following to next.config.js seems to have fixed the issue:

experimental: {
  appDir: false,
},

@skaraudio
Copy link

I was facing a similar issue after trying to upgrade locally for a Next app using a custom server. Adding the following to next.config.js seems to have fixed the issue:

experimental: {
  appDir: false,
},

Thank you!!

@lucasishuman
Copy link

Thanks for the config tips, all.

Next needs to add that to the pages docs if it's now explicitly required to 'opt out' of app directory...

https://nextjs.org/docs/pages/api-reference/next-config-js

n1ckoates added a commit to n1ckoates/blog that referenced this issue May 5, 2023
n1ckoates added a commit to n1ckoates/blog that referenced this issue May 5, 2023
* ⬆️ Bump next from 13.2.4 to 13.4.0

Bumps [next](https://github.com/vercel/next.js) from 13.2.4 to 13.4.0.
- [Release notes](https://github.com/vercel/next.js/releases)
- [Changelog](https://github.com/vercel/next.js/blob/canary/release.js)
- [Commits](vercel/next.js@v13.2.4...v13.4.0)

---
updated-dependencies:
- dependency-name: next
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* 🐛 Opt-out of appDir

- Workaround for vercel/next.js#49261

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Nick Oates <nick@nickoates.com>
@belgattitude
Copy link
Contributor

belgattitude commented May 5, 2023

Have the same issue after upgrade to nextjs 13.4.0 (from 13.3.4) - no app dir - no type module

image

The example repo is:

https://github.com/belgattitude/nextjs-monorepo-example (branch main)

The ci passes (https://github.com/belgattitude/nextjs-monorepo-example/actions/workflows/ci-nextjs-app.yml), vercel just started to break after upgrade.

If you want to try on vercel, you'll have to add ENABLE_EXPERIMENTAL_COREPACK=1 in the vercel env.

The deployment url: https://monorepo-nextjs-app.vercel.app/

Open to help if needed

PS:

@laubonghaudoi
Copy link
Author

laubonghaudoi commented May 12, 2023

It seems like this issue is happening again in 13.4.2. The error message is different tho, this time it's

Type error: 'MyComponent' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.

Local build is fine but Vercel deployment fails, same as 13.4.0

@imyuanli
Copy link

imyuanli commented May 12, 2023

Adding the ’ appDir: false‘ configuration item still has the same error
image

"next": "13.4.2"

@looterz
Copy link

looterz commented May 13, 2023

Adding the ’ appDir: false‘ configuration item still has the same error image

"next": "13.4.2"

Same here. I ended up removing it entirely since its "stable" and still get the issue. Tried forcing my pages to force-dynamic and it builds but I get errors in production.

@stephenasuncionDEV
Copy link

It seems like this issue is happening again in 13.4.2. The error message is different tho, this time it's

Type error: 'MyComponent' cannot be used as a JSX component.
Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.

Local build is fine but Vercel deployment fails, same as 13.4.0

I am also getting cannot be used as a JSX component. when using a dynamic import.

const Payments = dynamic(() => import("@/components/Account/Payments"), {
  loading: () => <Loading />,
});
...
<AccountLayout curPage={curPage}>
        {
          {
            payments: <Payments />,
            ...
          }[curPage]
        }
      </AccountLayout>

Error:

'Payments' cannot be used as a JSX component.
  Its element type 'ReactElement<any, any> | Component<{}, any, any> | null' is not a valid JSX element.
    Type 'Component<{}, any, any>' is not assignable to type 'Element | ElementClass | null'.
      Type 'Component<{}, any, any>' is not assignable to type 'ElementClass'.
        The types returned by 'render()' are incompatible between these types.
          Type 'React.ReactNode' is not assignable to type 'import(".../node_modules/@types/react-dom/node_modules/@types/react/index").ReactNode'.ts(2786)

@MathurAditya724
Copy link

Hey, I am facing the same issue in the latest build of nextjs. I have listed the issues and examples in greater detail on the Tanstack issues, check it out here.

Basically, it is not working in a mono repo created using nx, the build is failing.

@doug-shontz
Copy link

We are having the same issue as @MathurAditya724 using NX as well (>=v16). Our error is of the "Cannot read properties of null (reading 'useEffect')" variant and we are also using Tanstack Query (which is how I got to this issue). When I downgrade to Next 13.3.4 everything works correctly, but anything past 13.4.x generates the error.

@MathurAditya724
Copy link

Hey, just upgrade your next package to the latest version or the Canary version. We upgraded to ^13.4.4-canary.1, and everything started working like normal.

@busla
Copy link

busla commented May 24, 2023

updated to 13.4.4-canary.8 and nx/next:build executor started working again

@github-actions
Copy link
Contributor

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

14 participants