<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues?q=is%3Aissue">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behavior</h2>
<p dir="auto">The server should respond to requests without error. The server responds fine with NextJS 5.10.</p>
<h2 dir="auto">Current Behavior</h2>
<p dir="auto">The server responds 'Internal Server Error' to all requests.</p>
<p dir="auto">Below is the stack trace that gets logged to CloudWatch. Note the mix of forward and back slashes in the file path it is trying to resolve. I am running 'next build' (on windows) before deployment and have checked node_modules is also getting deployed.</p>
<p dir="auto"><code class="notranslate">Error: Cannot find module '/var/task/.next/dist/bundles\pages\_error.js' at Function.Module._resolveFilename (module.js:547:15) at Function.Module._load (module.js:474:25) at Module.require (module.js:596:17) at require (internal/module.js:11:18) at _callee$ (/var/task/node_modules/next/dist/server/require.js:87:46) at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:62:40) at Generator.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:296:22) at Generator.prototype.(anonymous function) [as next] (/var/task/node_modules/regenerator-runtime/runtime.js:114:21) at step (/var/task/node_modules/@babel/runtime/helpers/asyncToGenerator.js:12:30) at _next (/var/task/node_modules/@babel/runtime/helpers/asyncToGenerator.js:27:9) code: 'MODULE_NOT_FOUND'</code></p>
<h2 dir="auto">Steps to Reproduce (for bugs)</h2>
<ol dir="auto">
<li>Deploy NextJS V6 app using an express custom server to Lambda using aws-serverless-express.</li>
</ol>
<h2 dir="auto">Context</h2>
<p dir="auto">Works fine with NextJS V5.1.0. I am unable to upgrade to NextJS V6 because of this.</p>
<p dir="auto">next.config.js</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')

const withTypescript = require('@zeit/next-typescript');
const withSass = require('@zeit/next-sass');

module.exports = (phase, {defaultConfig}) =&gt; {
  return withTypescript(withSass({
    webpack(config, options) {
      return config;
    },
    publicRuntimeConfig: {
      API_HOST: (phase === PHASE_DEVELOPMENT_SERVER) ? 'http://localhost:4000' : 'https://api.xxxx'
    }
  }));
}"><pre class="notranslate"><code class="notranslate">const { PHASE_DEVELOPMENT_SERVER } = require('next/constants')

const withTypescript = require('@zeit/next-typescript');
const withSass = require('@zeit/next-sass');

module.exports = (phase, {defaultConfig}) =&gt; {
  return withTypescript(withSass({
    webpack(config, options) {
      return config;
    },
    publicRuntimeConfig: {
      API_HOST: (phase === PHASE_DEVELOPMENT_SERVER) ? 'http://localhost:4000' : 'https://api.xxxx'
    }
  }));
}
</code></pre></div>
<h2 dir="auto">Your Environment</h2>
<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>6.00</td>
</tr>
<tr>
<td>node</td>
<td>8.10</td>
</tr>
<tr>
<td>OS</td>
<td>AWS Linux AMI (Linux kernel version – 4.9.85-38.58.amzn1.x86_64)</td>
</tr>
</tbody>
</table>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/zeit/next.js/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h2 dir="auto">Expected Behavior</h2>


<h2 dir="auto">Current Behavior</h2>

<p dir="auto">I have custom route something like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    router.get('/feed/:id/subs', async (ctx, next) =&gt; {
      ....
      await n.render(ctx.req, ctx.res, '/feed/subs', query)
    })"><pre class="notranslate"><code class="notranslate">    router.get('/feed/:id/subs', async (ctx, next) =&gt; {
      ....
      await n.render(ctx.req, ctx.res, '/feed/subs', query)
    })
</code></pre></div>
<p dir="auto">And in the <code class="notranslate">getInitialProps</code> of page <code class="notranslate">/feed/subs</code> I throw error like:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="let error = new Error('没有权限')
error.statusCode = 401
throw error"><pre class="notranslate"><code class="notranslate">let error = new Error('没有权限')
error.statusCode = 401
throw error
</code></pre></div>

<p dir="auto">I can have error message shown correctly, but the status code would always 500, I think I should have the ability to change the status code.</p>
<h2 dir="auto">Context</h2>

<p dir="auto">I've tried to change status code after <code class="notranslate">render</code>, but no hope, response is finished after <code class="notranslate">render</code></p>

<h2 dir="auto">Your Environment</h2>

<table role="table">
<thead>
<tr>
<th>Tech</th>
<th>Version</th>
</tr>
</thead>
<tbody>
<tr>
<td>next</td>
<td>3.2.2</td>
</tr>
<tr>
<td>node</td>
<td>8.5</td>
</tr>
<tr>
<td>OS</td>
<td>MacOS</td>
</tr>
<tr>
<td>browser</td>
<td>any</td>
</tr>
<tr>
<td>etc</td>
<td></td>
</tr>
</tbody>
</table>