The shared hosting environment encountered an error during the Next JS build process

When I execute the command "npm run build" on my shared hosting server, it throws an error message: spawn ENOMEM. Interestingly, this command runs perfectly fine on my localhost and has been running smoothly on the hosting server for a few weeks until yesterday.

> <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="79d3cac4ced9c8edcbc1cdc1cd">[email protected]</a> build /home/user123/public_html
> next build

Creating an optimized production build ...internal/child_process.js:366
    throw errnoException(err, 'spawn');
    ^

Error: spawn ENOMEM
    at ChildProcess.spawn (internal/child_process.js:366:11)
    at spawn (child_process.js:551:9)
    at Object.fork (child_process.js:113:10)
    at ChildProcessWorker.initialize (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:137:44)
    at new ChildProcessWorker (/home/user123/public_html/node_modules/jest-worker/build/workers/ChildProcessWorker.js:127:10)
    at WorkerPool.createWorker (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:44:12)
    at new BaseWorkerPool (/home/user123/public_html/node_modules/jest-worker/build/base/BaseWorkerPool.js:82:27)
    at new WorkerPool (/home/user123/public_html/node_modules/jest-worker/build/WorkerPool.js:30:1)
    at new JestWorker (/home/user123/public_html/node_modules/jest-worker/build/index.js:131:26)
    at TaskRunner.run (/home/user123/public_html/node_modules/next/dist/build/webpack/plugins/terser-webpack-plugin/src/TaskRunner.js:3:166)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c5afb7b9b2ada6d0e1fdfafdfd">[email protected]</a> build: `next build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="e69c809b8e908480859e90949e80">[email protected]</a> build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/user123/.npm/_logs/2019-09-24T19_27_41_300Z-debug.log

In addition, here is the debug log:

0 info it worked if it ends with ok
1 verbose cli [ '/home/user123/node/bin/node',
1 verbose cli   '/home/user123/node/bin/npm',
1 verbose cli   'run',
1 verbose cli   'build' ]
2 info using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a8aecba3bbbba8afa8ae">[email protected]</a>
3 info using <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef82869282a083808384">[email protected]</a>
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5e329d81829b86">[email protected]</a>~prebuild: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="75180c061c01103514101004141010135e3">[email protected]</a>
6 info lifecycle <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="37536277736f74">[email protected]</a>~build: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="21196044214d"/></span><!--/data-cfemail--> kmZKmwnYGL2R7e4No</a></em></p><span>of</span>#1v1e9r4boug411<u>nAatuosed *

I am using express and Next.js for my project. Below is my server.js file:

const express = require( 'express' );
const next    = require( 'next' );

// Import middleware.
const routes = require( './routes' );

// Setup app.
const app     = next( { dev: 'production' !== process.env.NODE_ENV } );
const handle  = app.getRequestHandler();
const handler = routes.getRequestHandler( app );

app.prepare()
  .then( () => {

    // Create server.
    const server = express();

    // Use our handler for requests.
    server.use( handler );

    // Don't remove. Important for the server to work. Default route.
    server.get( '*', ( req, res ) => {
      return handle( req, res );
    } );

    // Get current port.
    const port = process.env.PORT || 8080;

    // Error check.
    server.listen( port, err => {
      if ( err ) {
        throw err;
      }

      // Server started successfully!
      console.log( `> Ready on port ${port}...` );
    } );
  } );

I have already checked the swap space and memory usage, and it appears to be fine:

             total       used       free     shared    buffers     cached
Mem:         31906      31330        575         21       2982      16900
-/+ buffers/cache:      11447      20459
Swap:         8191          0       8191

I also attempted using a command like

NODE_OPTIONS=--max-old-space-size=2048 npm run build
, but the issue persists.

If anyone has any insights or suggestions regarding what might be causing this error, I would greatly appreciate your input.

Answer №1

It appears to be linked to the latest release of NextJs, specifically version 9, as it is consuming excessive memory during the app building process. For detailed discussions about this issue, please refer to the following link: https://github.com/zeit/next.js/issues/7929

Fortunately, downgrading to version 8 seems to resolve the problem. Therefore, if you are looking for a temporary solution, consider reverting back to version 8.

In case downgrading doesn't alleviate the issue, another workaround involves disabling the minimization feature in the 'next.config.js' file. This will help reduce memory usage:

module.exports = {
    webpack: (config, options) => {
        config.optimization.minimize = false;
      return config
    }
  }

If excluding minimization is not desirable, an alternative approach I discovered with version 8 is that you can build your app locally and then transfer the already built folder to your shared hosting without needing to execute "next build" on the shared hosting server again. Unfortunately, this method did not work with version 9.

Note: The testing was conducted using NextJs version 8.1

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

waiting to display information until it is necessary

I am currently working on optimizing my website for improved loading speed and responsiveness. Users can scroll through up to 4k images, apply filters, and sort them based on their preferences. Below is the code snippet for my filtering function: function ...

Utilizing the protractor tool to navigate through menu options and access submenus efficiently

I am new to using Protractor and I'm struggling to write code that can select the menu, submenus, and click them within the div with id="navbar". Can someone please assist me with this issue? Unfortunately, I am facing difficulties posting the HTML co ...

The Tailwind CSS classes failed to load properly within the npm package

I recently developed an Npm package using Vite with React and TailwindCSS. The package is functioning properly, but I encountered an issue when installing it in a different project – the CSS styles are not being applied. Can anyone provide guidance on h ...

The markers on Google Maps are currently displaying in the wrong position, despite the latitude and longitude being correct

Utilizing the Google Maps API, I have implemented a system to dynamically add map markers tracking 2 of our company's vehicles. The website is developed in asp.net c# mvc with bootstrap 4.3.1. An ajax request retrieves the latest marker location from ...

Display buttons when hovering with React

Seeking assistance with implementing functionality in a React application where buttons for editing and deleting display only when the mouse hovers over the corresponding row. Currently, the implemented code displays these buttons in all rows on hover. Sn ...

Sending data and redirecting to a new URL by linking multiple responses together

As a beginner in javascript, I wanted to confirm if my code is appropriate. I am currently using JavaScript to handle a PUT request. My main goal is to return the updated Sequelize model as a response and then redirect the user back to the local /. Can I ...

Exclude the key-value pair for any objects where the value is null

Is there a way to omit one key-value pair if the value is null in the TypeScript code snippet below, which creates a new record in the Firestore database? firestore.doc(`users/${user.uid}`).set({ email: user.email, name: user.displayName, phone: ...

Issue with Website Rendering: Safari 4 exhibits display glitch showing temporary content before showing a blank white screen

Currently, I'm in the process of developing a specialized rails application. However, there seems to be an unusual rendering error that has been reported by Safari 4 users. It's quite peculiar because the page appears briefly but quickly disappea ...

Verbose output during the installation of Ionic@beta indicates success, however the Ionic@beta package has not been fully installed at this

Here are the details of my Version: npm : 3.9.0 cordova : 5.3.3 nodejs : v5.11.0 When I try to install Ionic@beta by using the command: npm i -g --verbose ionic@beta The response received in the cmd is as follows: C:\Users\thinkdigital ...

Is it possible for me to utilize this code for logging in through a dialog box?

Here is the code snippet I have on the client side: <p>Username:</p> <p><asp:TextBox ID="tbUsername" runat="server"></asp:TextBox></p> <p>Password:</p> <p><asp:TextBox ID="tbPassword" runat="server ...

MongoDB document queries that do not consider timezones

I have some files with dates saved in various time zones' offsets. [ { "ac":ISODate("2019-09-09T18:30:00.000Z") }, { "ac":ISODate("2019-09-09T12:00:00.000Z") }, { "ac":ISODate("2019-09-09T10:00:00.000Z") ...

MongoDB MongooseError: The `collection.aggregate()` method cannot be called until the initial connection is fully established

Check out my personal website that I created using NextJS and hosted on Vercel. The site connects to a MongoDB database through Mongoose in my NodeJS API. Recently, I've been encountering a strange error affecting only about 1% of the users: Mongoose ...

Issue with inheritance from Angular ModalCtrl to ServiceCtrl not functioning as expected

I've been working on linking models to services in order to update global models throughout my app, but it doesn't seem to be functioning as expected. Recently, I delved into AngularJS and I suspect that I may have misunderstood my code. From wh ...

Best approach to disentangle nowjs code from your application (written in coffee/js)

Is it advisable to separate my nowjs code from the main app file? everyone = require("now").initialize app, { socketio: { transports: ['xhr-polling', 'jsonp-polling'] } } everyone.now.distribute_event = (event, day) -> everyone.n ...

Warning: Unhandled promise rejection - The type error occurred because the property 'close' of the object is undefined

I am currently configuring node.js in order to test my JavaScript codes using the Jest JavaScript testing framework. Can anyone spot what I might have done incorrectly? package.json file { "name": "institute-jest", "version&quo ...

Incorporated asynchronous functionality, struggling to integrate it into the code

Previously, I used to utilize the following code for handling state: //get state MyClass.prototype.getState = function(key) { var value; switch(this._options.type){ case "cookie": value = $.cookie(key); ...

Tips for removing the Y-Axis entirely from a CanavasJS chart

I'm working with a canvasJS chart and my goal is to completely hide the Y-Axis. I've managed to remove the Y-Axis line and title in this JSFiddle example. I came across these properties to hide the Y-Axis title and line, but I'm struggling t ...

When making a GET request, `req.body` will consistently be found void of any

Why is my req.body always empty on a GET request in Express 4.13.3, but filled with correct data on POST requests? I couldn't find any explanation for this difference in the Express documentation. This is my current Express configuration: function o ...

Balancing the Demands on a Node

We are currently managing a C# Web API server and a Node Express server. Our C# server sends multiple requests to a specific route on the Node server, which performs complex tasks and often takes 6-8 seconds to complete. However, when we send hundreds of ...

Issue encountered while retrieving data in React Native app from an express server

I am currently in the process of building an android application that fetches data from a local server. I have encountered no errors thus far, but unfortunately, I am not receiving the requested data. To provide some context, my frontend is built using Rea ...