title: NextJS build occasionally fails then succeeds
body: <p>I'm playing around with NextJS and things appear to be fine when running in <code>development</code> but when I build the app it will sometimes complain about missing modules despite successfully compiling.</p>
  <p>Here is the output from a fail:</p>
  <pre><code>info  - Loaded env from /app/.env.local
  Creating an optimized production build  
  
  Compiled successfully.
  
  Automatically optimizing pages .
  Error occurred prerendering page &quot;/rental/10059872&quot;. Read more: https://err.sh/next.js/prerender-error
  Error: Cannot find module for page: /rental/[id]
      at pageNotFoundError (/app/node_modules/next/dist/next-server/server/require.js:1:384)
      at getPagePath (/app/node_modules/next/dist/next-server/server/require.js:2:82)
      at requirePage (/app/node_modules/next/dist/next-server/server/require.js:2:227)
      at loadComponents (/app/node_modules/next/dist/next-server/server/load-components.js:1:771)
      at Object.exportPage [as default] (/app/node_modules/next/dist/export/worker.js:14:188)
  
  &gt; Build error occurred
  Error: Export encountered errors on following paths:
          /rental/10051164
          /rental/10057826
          /rental/10059872
          /rental/10082307
          /rental/10138784
      at exportApp (/app/node_modules/next/dist/export/index.js:24:1103)
      at processTicksAndRejections (internal/process/task_queues.js:93:5)
      at async build (/app/node_modules/next/dist/build/index.js:37:218)
  </code></pre>
  <p>Here is the output from a successful build that happened on my third attempt despite changing nothing:</p>
  <pre><code>info  - Loaded env from /app/.env.local
  Creating an optimized production build  
  
  Compiled successfully.
  
  Automatically optimizing pages .Could not find files for /rental/[id] in .next/build-manifest.json
  Automatically optimizing pages  
  
  Page                              Size     First Load JS
  ┌ ● /                             3.89 kB        62.7 kB
  ├   /_app                         0 B            58.8 kB
  ├ ○ /404                          3.02 kB        61.9 kB
  ├ λ /api/rental/[id]              0 B            58.8 kB
  ├ λ /api/rental/new               0 B            58.8 kB
  ├ λ /api/results                  0 B            58.8 kB
  ├ ● /rental/[id]                  1.42 kB        60.2 kB
  ├   ├ /rental/10059872
  ├   ├ /rental/10051164
  ├   ├ /rental/10082307
  ├   └ [+2 more paths]
  └ ○ /rental/new                   54.2 kB         113 kB
  + First Load JS shared by all     58.8 kB
  ├ chunks/commons.90eb9f.js      10.2 kB
  ├ chunks/framework.9862e0.js    40.5 kB
  ├ chunks/main.68a017.js         6.73 kB
  ├ chunks/pages/_app.7abee3.js   280 B
  ├ chunks/webpack.f300b4.js      1.19 kB
  └ css/fafd01249af2219e34a0.css  194 B
  
  λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
  ○  (Static)  automatically rendered as static HTML (uses no initial props)
  ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
  
  Redirects
  
  ┌ source: /:path+/
  ├ destination: /:path+
  └ permanent: true
  </code></pre>
  <p>Any ideas why it occasionally fails?</p>