skip to Main Content

I just ran into the following error when trying to build my project. Basically, everything works fine (seemingly) in development, but then the following happens: trying to build.

next build
   ▲ Next.js 14.1.0
   - Environments: .env

 ✓ Linting and checking validity of types    
   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Collecting page data    
 ✓ Generating static pages (679/679)

> Build error occurred
Error: Invariant: page wasn't built
    at C:devworkprojectnode_modulesnextdistbuildindex.js:1727:47
    at Array.map (<anonymous>)
    at C:devworkprojectnode_modulesnextdistbuildindex.js:1724:84
    at async Span.traceAsyncFn (C:devworkprojectnode_modulesnextdisttracetrace.js:151:20)
    at async C:devworkprojectnode_modulesnextdistbuildindex.js:1343:17
    at async Span.traceAsyncFn (C:devworkprojectnode_modulesnextdisttracetrace.js:151:20)
    at async build (C:devworkprojectnode_modulesnextdistbuildindex.js:374:9)
    at async main (C:devworkprojectnode_modulesnextdistbinnext:155:5)
error Command failed with exit code 1.

What I find strange is that when I try to redeploy a previous build that was working, I get the same error.

Checking the error log on Vercel then, the following error occurs on all pages being built;

TypeError: Cannot destructure property 'auth' of 'e' as it is null.
    at u (/vercel/path0/.next/server/chunks/601.js:1:14818)
    at a (/vercel/path0/.next/server/chunks/601.js:1:15507)
    at s (/vercel/path0/.next/server/chunks/601.js:1:10354)
    at /vercel/path0/.next/server/chunks/601.js:1:6250
    at Object.Kc [as useMemo] (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:60:240)
    at exports.useMemo (/vercel/path0/node_modules/react/cjs/react.production.min.js:25:208)
    at /vercel/path0/.next/server/chunks/601.js:1:6166
    at Wc (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:73:362)
    at Z (/vercel/path0/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)

I am not really sure where to go from here; everything was working fine a few days ago even going back to an older working version gives these errors. The "Invariant: Page wasn’t built" error isn’t really helpful, and there is not much information about it on the internet. Does anyone have some pointers on what I can try? Thanks

2

Answers


  1. this error might be a result of passing a <Link> without href or setting href to an empty string, something like this <Link href={value ?? ''}>...</Link>

    Login or Signup to reply.
  2. This error "Error: Invariant: page wasn’t built" come up when you created two pages with same possibilities of slug.
    For Ex.

    Page with slug: "/one/two"

    from file: /pages/[…page].tsx file
    and another page created from file: /pages/one/[slug].tsx

    So for npm run dev, eventually both pages are accepted however at the time of page generation with npm run build, it generates the error of "Invariant: page wasn’t built".

    https://codesandbox.io/p/devbox/stackoverflow-test-2pppzr?file=%2Fpages%2F%5B…page%5D.tsx%3A6%2C27

    Check the above sandbox code with :

    file name: [...page].tsx
    line no.: 6
    code : page: ["OneNew", "two"]
    

    If I keep page "One" then run dev will work but build will throw the same error. However, if I change it to "OneNew" then the build is generated successfully.

    In your case, after your last build, some new dynamic pages are generated that have the same URL slug with a different file structure. so check the last created pages and you will get the issue for sure.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search