<h2 dir="auto">Problem</h2>
<p dir="auto">My team is maintaining a large front end application with the same file hierarchy as:-</p>
<ul dir="auto">
<li>component</li>
<li>pages</li>
</ul>
<p dir="auto">but we don't like it. We usually have multiple component that is only used by a single page resulting whenever we found bugs or wanted to modify a page, we have to navigate though component to find the components related to the page. Its a pain in developing. So, we prefer the approach of:-</p>
<ul dir="auto">
<li>pages
<ul dir="auto">
<li>page<br>
index.js
<ul dir="auto">
<li>component<br>
and we are looking for a new framework to use</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 dir="auto">Ideal case</h2>
<p dir="auto">We would name our pages and components differently</p>
<ul dir="auto">
<li>pages
<ul dir="auto">
<li>page<br>
index.page.js
<ul dir="auto">
<li>component<br>
component.component.js</li>
</ul>
</li>
</ul>
</li>
</ul>
<p dir="auto">We would use pagesGlobPattern to only render files ending with .page.js ignoring .component.js<br>
But then we would need another option to ask next to treat index.page.js as index.js</p>


<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>
<p dir="auto">Hey Zeit / team! First of all, thanks for all of the hard work on NextJS / Now it's a match made and heaven and I'm insanely excited to be able to migrate a large production app over to the platform.</p>


<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>
<p dir="auto">Builds should always be deployable via now and should pass remotely as long as they're passing locally. (considering we're not using any global modules, etc) .. I'm not sure if this is an issue with Next or with Now, but building my app locally works 100% of the time via <code class="notranslate">NODE_ENV=production next build</code> .. which is the step that I believe is failing remotely.</p>
<h2 dir="auto">Current Behavior</h2>
<p dir="auto">Sometimes when deploying our app, it will fail intermittently. Upon retrying, it will sometimes work, and other times not .. I'm not sure whether or not it's timing out, or what is actually causing these failures. I just get the obscure "Build Error"</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>latest</td>
</tr>
<tr>
<td>node</td>
<td>9.0.0</td>
</tr>
<tr>
<td>OS</td>
<td>OS X High Seirra</td>
</tr>
<tr>
<td>browser</td>
<td>N/A</td>
</tr>
</tbody>
</table>
<p dir="auto">This could be related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="208595332" data-permission-text="Title is private" data-url="https://github.com/vercel/next.js/issues/1195" data-hovercard-type="issue" data-hovercard-url="/vercel/next.js/issues/1195/hovercard" href="https://github.com/vercel/next.js/issues/1195">#1195</a> .. as I've had to add my own uglifyjs set up to my <code class="notranslate">next.config.js</code></p>
<p dir="auto">My <code class="notranslate">next.config.js</code> looks like this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const variables = require('./components/style-helpers/global-variables.js')
const UglifyJSPlugin = require('uglifyjs-webpack-plugin')

module.exports = {
  webpack: function (config, { dev }) {
    console.log(`Environment: ${process.env.NODE_ENV}`)

    if (!dev) {
      console.log('Uglifying JS')
      // remove this once this is resolved: https://github.com/zeit/next.js/issues/1195
      config.plugins = config.plugins.filter(p =&gt; p.constructor.name !== 'UglifyJsPlugin')
      config.plugins.push(
        new UglifyJSPlugin({
          parallel: true
        })
      )
    } else {
      // https://webpack.js.org/configuration/devtool/
      config.devtool = 'source-map'
    }

    config.module.rules.push(
      {
        test: /\.(jpg|svg|png|woff)$/,
        loader: 'url-loader?limit=25000'
      },
      {
        test: /\.css$/,
        use: [
          {
            loader: 'emit-file-loader',
            options: {
              name: 'dist/[path][name].[ext]'
            }
          },
          'babel-loader',
          'styled-modules/loader',
          'css-loader?modules',
          {
            loader: 'postcss-loader',
            options: {
              ident: 'postcss',
              plugins: (loader) =&gt; [
                require('postcss-custom-properties')({ variables, warnings: false, strict: false }),
                require('postcss-easy-import')({prefix: '_'}),
                require('postcss-cssnext')(),
                require('postcss-nested')()
              ]
            }
          }
        ]
      }
    )

    return config
  }
}"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">variables</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'./components/style-helpers/global-variables.js'</span><span class="pl-kos">)</span>
<span class="pl-k">const</span> <span class="pl-v">UglifyJSPlugin</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'uglifyjs-webpack-plugin'</span><span class="pl-kos">)</span>

<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-en">webpack</span>: <span class="pl-k">function</span> <span class="pl-kos">(</span><span class="pl-s1">config</span><span class="pl-kos">,</span> <span class="pl-kos">{</span> dev <span class="pl-kos">}</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">`Environment: <span class="pl-s1"><span class="pl-kos">${</span><span class="pl-s1">process</span><span class="pl-kos">.</span><span class="pl-c1">env</span><span class="pl-kos">.</span><span class="pl-c1">NODE_ENV</span><span class="pl-kos">}</span></span>`</span><span class="pl-kos">)</span>

    <span class="pl-k">if</span> <span class="pl-kos">(</span><span class="pl-c1">!</span><span class="pl-s1">dev</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
      <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'Uglifying JS'</span><span class="pl-kos">)</span>
      <span class="pl-c">// remove this once this is resolved: https://github.com/zeit/next.js/issues/1195</span>
      <span class="pl-s1">config</span><span class="pl-kos">.</span><span class="pl-c1">plugins</span> <span class="pl-c1">=</span> <span class="pl-s1">config</span><span class="pl-kos">.</span><span class="pl-c1">plugins</span><span class="pl-kos">.</span><span class="pl-en">filter</span><span class="pl-kos">(</span><span class="pl-s1">p</span> <span class="pl-c1">=&gt;</span> <span class="pl-s1">p</span><span class="pl-kos">.</span><span class="pl-c1">constructor</span><span class="pl-kos">.</span><span class="pl-c1">name</span> <span class="pl-c1">!==</span> <span class="pl-s">'UglifyJsPlugin'</span><span class="pl-kos">)</span>
      <span class="pl-s1">config</span><span class="pl-kos">.</span><span class="pl-c1">plugins</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span>
        <span class="pl-k">new</span> <span class="pl-v">UglifyJSPlugin</span><span class="pl-kos">(</span><span class="pl-kos">{</span>
          <span class="pl-c1">parallel</span>: <span class="pl-c1">true</span>
        <span class="pl-kos">}</span><span class="pl-kos">)</span>
      <span class="pl-kos">)</span>
    <span class="pl-kos">}</span> <span class="pl-k">else</span> <span class="pl-kos">{</span>
      <span class="pl-c">// https://webpack.js.org/configuration/devtool/</span>
      <span class="pl-s1">config</span><span class="pl-kos">.</span><span class="pl-c1">devtool</span> <span class="pl-c1">=</span> <span class="pl-s">'source-map'</span>
    <span class="pl-kos">}</span>

    <span class="pl-s1">config</span><span class="pl-kos">.</span><span class="pl-c1">module</span><span class="pl-kos">.</span><span class="pl-c1">rules</span><span class="pl-kos">.</span><span class="pl-en">push</span><span class="pl-kos">(</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">test</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\.</span><span class="pl-kos">(</span>jpg<span class="pl-c1">|</span>svg<span class="pl-c1">|</span>png<span class="pl-c1">|</span>woff<span class="pl-kos">)</span><span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span>
        <span class="pl-c1">loader</span>: <span class="pl-s">'url-loader?limit=25000'</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">test</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\.</span>css<span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span>
        <span class="pl-c1">use</span>: <span class="pl-kos">[</span>
          <span class="pl-kos">{</span>
            <span class="pl-c1">loader</span>: <span class="pl-s">'emit-file-loader'</span><span class="pl-kos">,</span>
            <span class="pl-c1">options</span>: <span class="pl-kos">{</span>
              <span class="pl-c1">name</span>: <span class="pl-s">'dist/[path][name].[ext]'</span>
            <span class="pl-kos">}</span>
          <span class="pl-kos">}</span><span class="pl-kos">,</span>
          <span class="pl-s">'babel-loader'</span><span class="pl-kos">,</span>
          <span class="pl-s">'styled-modules/loader'</span><span class="pl-kos">,</span>
          <span class="pl-s">'css-loader?modules'</span><span class="pl-kos">,</span>
          <span class="pl-kos">{</span>
            <span class="pl-c1">loader</span>: <span class="pl-s">'postcss-loader'</span><span class="pl-kos">,</span>
            <span class="pl-c1">options</span>: <span class="pl-kos">{</span>
              <span class="pl-c1">ident</span>: <span class="pl-s">'postcss'</span><span class="pl-kos">,</span>
              <span class="pl-en">plugins</span>: <span class="pl-kos">(</span><span class="pl-s1">loader</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">[</span>
                <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'postcss-custom-properties'</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">{</span> variables<span class="pl-kos">,</span> <span class="pl-c1">warnings</span>: <span class="pl-c1">false</span><span class="pl-kos">,</span> <span class="pl-c1">strict</span>: <span class="pl-c1">false</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
                <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'postcss-easy-import'</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-c1">prefix</span>: <span class="pl-s">'_'</span><span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
                <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'postcss-cssnext'</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
                <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'postcss-nested'</span><span class="pl-kos">)</span><span class="pl-kos">(</span><span class="pl-kos">)</span>
              <span class="pl-kos">]</span>
            <span class="pl-kos">}</span>
          <span class="pl-kos">}</span>
        <span class="pl-kos">]</span>
      <span class="pl-kos">}</span>
    <span class="pl-kos">)</span>

    <span class="pl-k">return</span> <span class="pl-s1">config</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">And this has been the intermitten  experience I've been having:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://camo.githubusercontent.com/9a6487740b796375737b352901542532149e1341e68dff9164feffaf809d262e/687474703a2f2f642e70722f692f5651356339422b"><img src="https://camo.githubusercontent.com/9a6487740b796375737b352901542532149e1341e68dff9164feffaf809d262e/687474703a2f2f642e70722f692f5651356339422b" alt="" data-canonical-src="http://d.pr/i/VQ5c9B+" style="max-width: 100%;"></a></p>
<p dir="auto">I can provide any additional information if I left anything out, but this has been kicking my butt so I'd really love if I could get some other eyes on this!</p>