title: AWS CodeBuild not producing any artifacts when build runs `next build` successfully
body: <p>I am using NextJS and attempting to do CI to build and deploy onto AWS Beanstalk.</p>
  <p>This is my <code>buildspec.yml</code></p>
  <pre class="lang-yaml prettyprint-override"><code>version: 0.2
  env:
    variables:
      NODE_ENV: &quot;production&quot;
  phases:
    pre_build:
      commands:
        - echo Installing dependencies
        - npm install
    build:
      commands:
        - echo Building nextjs app
        - npm run build
    post_build:
      commands:
        - echo Build completed on `date`
  artifacts:
    files:
      - '**/*'
  </code></pre>
  <p>I am monitoring the logs and there are no errors, but there are no artifacts being produced by the <strong>Build</strong> stage. So once the pipeline moves onto the <strong>Deploy</strong> stage. I get this error in the logs:</p>
  <pre><code>----------------------------------------
  /var/log/web.stdout.log
  ----------------------------------------
  Nov 30 01:47:31 ip-172-31-50-67 web: at /var/app/current/node_modules/next/dist/bin/next:26:341
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! code ELIFECYCLE
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! errno 1
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! with-typescript@1.0.0 start: `next start`
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! Exit status 1
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR!
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! Failed at the with-typescript@1.0.0 start script.
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR! A complete log of this run can be found in:
  Nov 30 01:47:31 ip-172-31-50-67 web: npm ERR!     /home/webapp/.npm/_logs/2020-11-30T01_47_31_607Z-debug.log
  Nov 30 01:47:32 ip-172-31-50-67 web: &gt; with-typescript@1.0.0 start /var/app/current
  Nov 30 01:47:32 ip-172-31-50-67 web: &gt; next start
  Nov 30 01:47:32 ip-172-31-50-67 web: Error: Could not find a valid build in the '/var/app/current/.next' directory! Try building your app with 'next build' before starting the server.
  Nov 30 01:47:32 ip-172-31-50-67 web: at Server.readBuildId (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:137:355)
  Nov 30 01:47:32 ip-172-31-50-67 web: at new Server (/var/app/current/node_modules/next/dist/next-server/server/next-server.js:3:120)
  Nov 30 01:47:32 ip-172-31-50-67 web: at createServer (/var/app/current/node_modules/next/dist/server/next.js:2:638)
  Nov 30 01:47:32 ip-172-31-50-67 web: at start (/var/app/current/node_modules/next/dist/server/lib/start-server.js:1:323)
  Nov 30 01:47:32 ip-172-31-50-67 web: at nextStart (/var/app/current/node_modules/next/dist/cli/next-start.js:19:125)
  </code></pre>
  <p>I don't understand what more I can do? I have tried changing the <strong>Artifacts</strong> settings for the <strong>Build</strong> stage to encrypted and unencrypted, I have tried <em>No cache</em>, <em>Local</em>, and <em>Amazon S3</em> with a Cache Bucket. None of these seem to produce any artifacts.</p>
  <p>Can anyone point me to what I'm doing wrong?</p>