Create-react-app: Failed builds when running in CI Environments

Created on 9 Aug 2018  路  11Comments  路  Source: facebook/create-react-app

I'm not sure if this is the right place for this or not, but I am curious if anyone else is having any issues running their build from within circleci?

I have tried using both yarn and npm as well as versions 1.1.4 and 2.0.0-next.3e165448 all of which produce the same error. In all cases I am just running the build target

Is there a way to get more verbose logging on the build so that I can troubleshoot this more?

The error I am seeing is

events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:364:12)
    at PoolWorker.writeJson (/home/circleci/project/node_modules/thread-loader/dist/WorkerPool.js:89:22)
    at PoolWorker.run (/home/circleci/project/node_modules/thread-loader/dist/WorkerPool.js:69:12)
    at WorkerPool.distributeJob (/home/circleci/project/node_modules/thread-loader/dist/WorkerPool.js:326:20)
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/queue.js:10:5
    at Object.process (/home/circleci/project/node_modules/thread-loader/node_modules/async/internal/queue.js:175:17)
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/queue.js:115:15
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/onlyOnce.js:12:16
    at callback (/home/circleci/project/node_modules/thread-loader/dist/WorkerPool.js:163:21)
    at /home/circleci/project/node_modules/thread-loader/dist/WorkerPool.js:190:15
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/map.js:32:9
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/once.js:12:16
    at replenish (/home/circleci/project/node_modules/thread-loader/node_modules/async/internal/eachOfLimit.js:61:25)
    at iterateeCallback (/home/circleci/project/node_modules/thread-loader/node_modules/async/internal/eachOfLimit.js:50:17)
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/onlyOnce.js:12:16
    at /home/circleci/project/node_modules/thread-loader/node_modules/async/internal/map.js:29:13
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{ Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }
{ Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }
ERROR: "build-js" exited with 1.
{ Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
{ Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }
Exited with code 1
bug

Most helpful comment

If anyone is running with create-react-app-rewired I added this config to fix my CI builds

 module.exports = {
   webpack: function(config, env) {
     if (process.env.CI) {
      const threadLoader = config.module.rules[3].oneOf[1].use[0];
      config.module.rules[3].oneOf[1].use[0] = {
        loader: threadLoader,
        options: {
          workers: process.env.CIRCLE_NODE_TOTAL
        }
      }
    }
     return config;
  }
 };

All 11 comments

Same problem, on TravisCI

> react-scripts build
Creating an optimized production build...
events.js:183
      throw er; // Unhandled 'error' event
      ^
Error: This socket has been ended by the other party
    at Socket.writeAfterFIN [as write] (net.js:364:12)
    at PoolWorker.writeJson (/home/travis/build/stadline/project/node_modules/thread-loader/dist/WorkerPool.js:85:22)
    at PoolWorker.run (/home/travis/build/stadline/project/node_modules/thread-loader/dist/WorkerPool.js:65:12)
    at WorkerPool.distributeJob (/home/travis/build/stadline/project/node_modules/thread-loader/dist/WorkerPool.js:329:20)
    at /home/travis/build/stadline/project/node_modules/async/queue.js:10:5
    at Object.process (/home/travis/build/stadline/project/node_modules/async/internal/queue.js:175:17)
    at /home/travis/build/stadline/project/node_modules/async/internal/queue.js:115:15
    at /home/travis/build/stadline/project/node_modules/async/internal/onlyOnce.js:12:16
    at callback (/home/travis/build/stadline/project/node_modules/thread-loader/dist/WorkerPool.js:159:21)
    at /home/travis/build/stadline/project/node_modules/thread-loader/dist/WorkerPool.js:186:15
    at /home/travis/build/stadline/project/node_modules/async/internal/map.js:32:9
    at /home/travis/build/stadline/project/node_modules/async/internal/once.js:12:16
    at replenish (/home/travis/build/stadline/project/node_modules/async/internal/eachOfLimit.js:61:25)
    at iterateeCallback (/home/travis/build/stadline/project/node_modules/async/internal/eachOfLimit.js:50:17)
    at /home/travis/build/stadline/project/node_modules/async/internal/onlyOnce.js:12:16
    at /home/travis/build/stadline/project/node_modules/async/internal/map.js:29:13
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @app/[email protected] build: `react-scripts build`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the @app/[email protected] 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/travis/.npm/_logs/2018-08-13T14_47_08_752Z-debug.log
{ Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }

I removed thead-loader from webpack.config.dev.js (for src and node_modules) and the tests pass!

Is it possible not to use this loader when CI=true ?

Related topics:
https://github.com/facebook/create-react-app/pull/4562
https://github.com/facebook/create-react-app/pull/4582

I can confirm @alex-pex findings.

I ejected my app, removed the thread-loader from webpack.config.prod.js and now the build succeeds on CircleCI.

Is there a way to optionally configure use of this loader so that I don't have to eject?

Working with CircleCI support we found this issue:

from thread-loader

options: {
      // the number of spawned workers, defaults to number of cpus
      workers: 2,

from CircleCI

The issue with this on Dockerized services such as CircleCI is that the container thinks it has access to all of the hosts cores, although its being limited down to 4 by another process.

Perhaps this value should get set when CI:true to something lower, or expose an environment variable that would allow overriding that value.

From TravisCI https://docs.travis-ci.com/user/common-build-problems/#my-build-script-is-killed-without-any-error

Sometimes, you鈥檒l see a build script being causing an error [...]. This is usually caused by the script or one of the programs it runs exhausting the memory available in the build sandbox, which is currently 3GB. Plus, there are two cores available, bursted.

A suggested fix https://github.com/travis-ci/travis-ci/issues/4696#issuecomment-210275203

In Python, one way to obtain the number of cores available for a Travis job, other than hard-coding '2', is to use psutil's Process.cpu_affinity. On travis the following gives the correct answer

len(psutil.Process().cpu_affinity())
2

thanks @alex-pex and @troyschneringer

I had slightly the same problem and fixed it by adding workers: 2 in the webpack.config.prod.js file. I'm on CircleCI and also ejected from CRA with new webpack configuration.

Creating an optimized production build...
events.js:165
      throw er; // Unhandled 'error' event
      ^

Error: write EPIPE
    at WriteWrap.afterWrite [as oncomplete] (net.js:844:14)
Emitted 'error' event at:
    at onwriteError (_stream_writable.js:431:12)
    at onwrite (_stream_writable.js:453:5)
    at _destroy (internal/streams/destroy.js:39:7)
    at Socket._destroy (net.js:548:3)
    at Socket.destroy (internal/streams/destroy.js:32:8)
    at WriteWrap.afterWrite [as oncomplete] (net.js:846:10)
npm { Error: EPIPE: broken pipe, write errno: -32, code: 'EPIPE', syscall: 'write' }
ERR! code ELIFECYCLE
npm ERR! errno 1

@sambegin based on feedback from Circle Support I used the following:

workers: process.env.CIRCLE_NODE_TOTAL

which is the effective number of CPUs available to your build. Minor change, but if you have more resources available it will use the max.

If anyone is running with create-react-app-rewired I added this config to fix my CI builds

 module.exports = {
   webpack: function(config, env) {
     if (process.env.CI) {
      const threadLoader = config.module.rules[3].oneOf[1].use[0];
      config.module.rules[3].oneOf[1].use[0] = {
        loader: threadLoader,
        options: {
          workers: process.env.CIRCLE_NODE_TOTAL
        }
      }
    }
     return config;
  }
 };

Is this being reprioritized? I'm also having the same issues.

@jedmao checkout 2.0. I updated last week and it resolved this issue.

threadLoader was removed in 2.0.x, please update if possible or file a new issue if you are still having difficulty.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

barcher picture barcher  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

rdamian3 picture rdamian3  路  3Comments

alleroux picture alleroux  路  3Comments

AlexeyRyashencev picture AlexeyRyashencev  路  3Comments