Nx: Task format:write -> Error: Command line too long

Created on 22 Jan 2020  路  3Comments  路  Source: nrwl/nx

Expected Behavior

npm run format:write should complete without errors

Current Behavior

npm run format:write fails with error "Command line too long"

Failure Information (for bugs)

We have several long library + path + file names, that result in a command line for prettier that is too long.

NX already uses chunks (see: packages/schematics/src/command-line/format.ts), but the chuck size of 70 is too large for us.

When we decrease the chunk size to 50, all is well, and format:write runs happily.

Steps to Reproduce

Please provide detailed steps for reproducing the issue.

  1. Have very long library names + paths + files (in average above 118 characters, preferably longer), and at least 70 of 'm.
  2. Run npm run format:write
  3. Observe the "Command line too long" error

Context

I'm using NX 8.0, but verified that the latest code still uses a chunk side of 70.

Failure Logs

Full log available on request, but basically:

The command line is too long.
C:\Data\shared-workspace\node_modules\@nrwl\workspace\node_modules\yargs\yargs.js:1109
      else throw err
           ^
Error: Command failed: node "C:\Data\shared-workspace\node_modules\@nrwl\workspace\node_modules\prettier\bin-prettier.js" --write <lots and lots of files here>
    at checkExecSyncError (child_process.js:610:11)
    at Object.execSync (child_process.js:646:15)
    at write (C:\Data\shared-workspace\node_modules\@nrwl\workspace\src\command-line\format.js:84:25)
    at C:\Data\shared-workspace\node_modules\@nrwl\workspace\src\command-line\format.js:42:40
    at Array.forEach (<anonymous>)
    at Object.format (C:\Data\shared-workspace\node_modules\@nrwl\workspace\src\command-line\format.js:42:23)
    at Object.handler (C:\Data\shared-workspace\node_modules\@nrwl\workspace\src\command-line\nx-commands.js:72:98)
    at Object.runCommand (C:\Data\shared-workspace\node_modules\@nrwl\workspace\node_modules\yargs\lib\command.js:235:44)
    at Object.parseArgs [as _parseArgs] (C:\Data\shared-workspace\node_modules\@nrwl\workspace\node_modules\yargs\yargs.js:1022:30)
    at Object.get [as argv] (C:\Data\shared-workspace\node_modules\@nrwl\workspace\node_modules\yargs\yargs.js:965:21) {
  status: 1,
  signal: null,
  output: [ null, null, null ],
  pid: 8968,
  stdout: null,
  stderr: null
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] format:write: `nx format:write`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] format:write 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!     C:\Users\****\AppData\Roaming\npm-cache\_logs\2020-01-22T09_18_07_616Z-debug.log
Process finished with exit code 1
community misc bug

Most helpful comment

This is a relatively easy fix. Would someone from the community like to contribute a fix?

All 3 comments

This is a relatively easy fix. Would someone from the community like to contribute a fix?

@FrozenPandaz Thanks for the fix.

I was wondering though, wouldn't it be possible to do this a bit more intelligently, by calculating what the length would be, adding additional chucks as space permits?

@FrozenPandaz I am getting this issue in 8.4.8, do I need to move to 9.3 version ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

zpydee picture zpydee  路  3Comments

SWGeekPD picture SWGeekPD  路  3Comments

Svancara picture Svancara  路  3Comments

danieldanielecki picture danieldanielecki  路  3Comments

ZempTime picture ZempTime  路  3Comments