Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weird error MSB6006: "cmd.exe" exited with code 1 on some packages #1151

Closed
jviotti opened this issue Mar 20, 2017 · 14 comments
Closed

Weird error MSB6006: "cmd.exe" exited with code 1 on some packages #1151

jviotti opened this issue Mar 20, 2017 · 14 comments

Comments

@jviotti
Copy link
Member

jviotti commented Mar 20, 2017

We've been facing a very strange issue at Etcher (https://github.com/resin-io/etcher). We have node-sass as a development dependency, and lzma-native as a production dependency.

When node-gyp was updated to v3.6.0, node-sass picked up this change, causing lzma-native to fail with the following error on Windows:

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\projects\etcher\node_modules\lzma-native\build\liblzma.vcxproj]

So to make it clear, after the node-gyp upgrade on a development dependency (node-sass), a totally unrelated production dependency, lzma-native, suddenly starts to fail on Windows. What's even more strange is that node-sass compiles just fine, and removing node-sass from the development dependencies causes lzma-native to start working again. As a fix, we've started shrinkwrapping development dependencies as well, and locking node-gyp to v3.5.0, which makes everything work again.

The problem seems to have been introduced by ae141e1, however I don't understand why.

See balena-io/etcher#1191. You can probably reproduce by cloning Etcher, checking out a commit before such fix, and running make electron-develop (which is a Makefile target that we use to pass some node-gyp options to npm, run bower, etc).

jviotti pushed a commit to balena-io/etcher that referenced this issue Mar 20, 2017
We've been recently hitting a weird `lzma-native` build error on Windows
(both locally and on Appveyor CI):

```
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  build
  The input line is too long.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\projects\etcher\node_modules\lzma-native\build\liblzma.vcxproj]
```

After a lot of experimentation, we realised the issue was gone if we
removed `node-sass` from the development dependencies.

The issue is that `node-gyp` was recently upgraded to v3.6.0, which was
picked up by `node-sass`, which declares `node-gyp` as a dependency. For
some reason, if `node-sass` causes `node-gyp` to be updated, then
`lzma-native` fails with the above cryptic error.

I was able to trace down the error to the following `node-gyp` commit:

nodejs/node-gyp@ae141e1

As a solution, this commit starts to shrinkwrap development
dependencies, and locks `node-gyp` to v3.5.0 until the issue is fixed.

Fixes: addaleax/lzma-native#30
See: nodejs/node-gyp#1151
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
jviotti pushed a commit to balena-io/etcher that referenced this issue Mar 20, 2017
We've been recently hitting a weird `lzma-native` build error on Windows
(both locally and on Appveyor CI):

```
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  build
  The input line is too long.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\projects\etcher\node_modules\lzma-native\build\liblzma.vcxproj]
```

After a lot of experimentation, we realised the issue was gone if we
removed `node-sass` from the development dependencies.

The issue is that `node-gyp` was recently upgraded to v3.6.0, which was
picked up by `node-sass`, which declares `node-gyp` as a dependency. For
some reason, if `node-sass` causes `node-gyp` to be updated, then
`lzma-native` fails with the above cryptic error.

I was able to trace down the error to the following `node-gyp` commit:

nodejs/node-gyp@ae141e1

As a solution, this commit starts to shrinkwrap development
dependencies, and locks `node-gyp` to v3.5.0 until the issue is fixed.

Fixes: addaleax/lzma-native#30
See: nodejs/node-gyp#1151
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
@lurch
Copy link

lurch commented Mar 20, 2017

The problem seems to have been introduced by ae141e1, however I don't understand why.

Hmm, I wonder if the problem might be that this part of the change:

  function findMsbuild () {
    if (config.variables.msbuild_path) {
      command = config.variables.msbuild_path

means that the MSBuild command is now run with its full-path "C:\Program Files (x86)\MSBuild\...\MSBuild.exe", whereas previously it was just run as MSBuild.exe, and this additional "C:\Program Files (x86)\MSBuild\..." is now just enough to push the lzma-native compilation command over the cmd.exe command-line length limit on Windows? http://stackoverflow.com/questions/3205027/maximum-length-of-command-line-string

@bnoordhuis
Copy link
Member

cc @refack @joaocgreis

@refack
Copy link
Contributor

refack commented Mar 20, 2017

hmmm... giving this some thought...

@refack
Copy link
Contributor

refack commented Mar 20, 2017

It's not a "length of command line" issue, it's a "not run from VS console" issue.
The lzma-native build calls lib.exe which is not in the path unless vsvarsall.bat (or it's derivatives) is run.
Up till node-gyp:v3.5.x the whole thing would fail. Now we can find & call msbuild.exe in the general case, but than we fail if the build is complicated ;(

@refack
Copy link
Contributor

refack commented Mar 20, 2017

Scratch that!
It's probably a bug in GYP. It erroneously escapes the action command...
from:

'action': [
  'lib -def:"<(module_root_dir)\\deps\\doc\\liblzma.def" -out:"<(module_root_dir)\\deps\\bin_x86-64\\lzma.lib" -machine:x64 && if not exist <(dlldir) mkdir <(dlldir) && copy "<(module_root_dir)\\deps\\bin_x86-64\\liblzma.dll" "<(dlldir)\\liblzma.dll"'
]

to: (extra &quot; breaks cmd syntax)

call call &quot;lib -def:&quot;C:\code\3party\lzma-native\deps\doc\liblzma.def&quot; -out:&quot;C:\code\3party\lzma-native\deps\bin_x86-64\lzma.lib&quot; -machine:x64 &amp;&amp; if not exist C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64 mkdir C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64 &amp;&amp; copy &quot;C:\code\3party\lzma-native\deps\bin_x86-64\liblzma.dll&quot; &quot;C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64\liblzma.dll&quot;&quot;&#xD;&#xA;if %errorlevel% neq 0 exit /b %errorlevel%

Instead of

call call lib -def:&quot;C:\code\3party\lzma-native\deps\doc\liblzma.def&quot; -out:&quot;C:\code\3party\lzma-native\deps\bin_x86-64\lzma.lib&quot; -machine:x64 &amp;&amp; if not exist C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64 mkdir C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64 &amp;&amp; copy &quot;C:\code\3party\lzma-native\deps\bin_x86-64\liblzma.dll&quot; &quot;C:\code\3party\lzma-native\binding-v2.0.0-node-v51-win32-x64\liblzma.dll&quot;&#xD;&#xA;if %errorlevel% neq 0 exit /b %errorlevel%

@jviotti
Copy link
Member Author

jviotti commented Mar 20, 2017

Awesome, great to hear you found the root cause of this issue! BTW, could you explain why in our case lzma-native started failing after node-gyp was upgraded by node-sass? I'm assuming that such upgrade caused lzma-native to start re-using node-sass's node-gyp version, which built node-sass fine, but caused errors on lzma-native because lzma-native uses lib.exe during build.

Is this correct?

jviotti pushed a commit to balena-io/etcher that referenced this issue Mar 20, 2017
* chore: fix `lzma-native` build issues on Windows

We've been recently hitting a weird `lzma-native` build error on Windows
(both locally and on Appveyor CI):

```
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
  build
  The input line is too long.

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(171,5): error MSB6006: "cmd.exe" exited with code 1. [C:\projects\etcher\node_modules\lzma-native\build\liblzma.vcxproj]
```

After a lot of experimentation, we realised the issue was gone if we
removed `node-sass` from the development dependencies.

The issue is that `node-gyp` was recently upgraded to v3.6.0, which was
picked up by `node-sass`, which declares `node-gyp` as a dependency. For
some reason, if `node-sass` causes `node-gyp` to be updated, then
`lzma-native` fails with the above cryptic error.

I was able to trace down the error to the following `node-gyp` commit:

nodejs/node-gyp@ae141e1

As a solution, this commit starts to shrinkwrap development
dependencies, and locks `node-gyp` to v3.5.0 until the issue is fixed.

Fixes: addaleax/lzma-native#30
See: nodejs/node-gyp#1151
Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>

* chore: ensure some modules in npm-shrinkwrap stay at specific versions

* Address code review comments

Signed-off-by: Juan Cruz Viotti <jviotti@openmailbox.org>
@refack
Copy link
Contributor

refack commented Mar 20, 2017

node-gyp come with npm. It's a tool that compiles "native bindings" for some modules.
Unfortunately native bindings need to be re-compiled for every version of node (or in this case electron).
lzma-native has an online cache of precompiled bindings, seems like the new version couldn't find a precompiled pack for your platform. In that case it tries to compile it with node-gyp which triggered the bug (bug might have been there for a while)

@addaleax
Copy link
Member

@refack Yeah, but it’s still a curious thing how the node-sass upgrade made the difference?

@lurch
Copy link

lurch commented Mar 21, 2017

I'm afraid I'll have to disagree with the (bug might have been there for a while) comment.
Up until 5 days ago all our Windows CI builds were working fine on Appveyor (including building lzma-native from source) but then all of a sudden (after the release of node-gyp 3.6.0) all our Windows CI builds started failing.

And our workaround for the problem in balena-io/etcher#1191 was to basically version-lock node-gyp to 3.5.0 which got everything working again.

@refack
Copy link
Contributor

refack commented Mar 21, 2017

Up until 5 days ago all our Windows CI builds were working fine on Appveyor (including building lzma-native from source) but then all of a sudden (after the release of node-gyp 3.6.0) all our Windows CI builds started failing.

I said might... 🤷
I'm still digging...

refack referenced this issue Mar 21, 2017
Microsoft's chakracore engine is dependent on Windows SDK, and build
tools should know the version installed on user machine. This change
adds those dependencies in node-gyp tools. Below is the summary:

* Configure msvs_windows_target_platform_version to use the right
  Windows SDK.

* Configure msvs_use_library_dependency_inputs to export symbols
  correctly (otherwise functions not used by node.exe but might be
  needed by native addon modules could be optimized away by linker).

These changes were originally made in nodejs/node#4765, but as @shigeki
mentioned, it was more sensible to send these changes as PR to node-gyp
repo.

PR-URL: #873
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@refack
Copy link
Contributor

refack commented Mar 21, 2017

Found it
Added escaping of custom actions, which may lead to broken commands
/cc @kunalspathak

@kunalspathak
Copy link
Member

Thanks @refack for the investigation. I went back and checked and it seems the quote_cmd issue was fixed in node-chakracore but #873 was not updated with the fix. I will send another PR to fix this.

@rvagg
Copy link
Member

rvagg commented Apr 30, 2017

resolved in @3.6.1

refack added a commit to refack/node-gyp that referenced this issue May 17, 2017
hideo55 added a commit to hideo55/node-unqlite that referenced this issue Jun 1, 2017
Changelog diff:

diff --git a/History.md b/History.md
index 4fab6d9..2132507 100644
--- a/History.md
+++ b/History.md
@@ -1,5 +1,11 @@
 # Revision history for unqlite

+0.3.5 / 2017-06-01
+==================
+
+   * Add workaround for gyp issue: nodejs/node-gyp#1151
+   * Use Nan::ForceSet() instead of v8::Object::ForceSet()
+
 0.3.4 / 2016-06-29
 ==================
@marcelfalliere
Copy link

Having the same problem in 3.6.2

$ npm install


> ref@1.3.5 install C:\Users\xavier\Documents\Carestream\server\node_modules\ref
> node-gyp rebuild


C:\Users\xavier\Documents\Carestream\server\node_modules\ref>if not defined npm_config_node_gyp (node "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild )  else (node "C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\bin\node-gyp.js" rebuild )
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.CppCommon.targets(356,5): error MSB6006: "CL.exe" exited with code -1073741515. [C:\Users\xavier\Documents\Carestream\server\node_modules\ref\build\binding.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\MSBuild\14.0\bin\msbuild.exe` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onExit (C:\Program Files (x86)\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:258:23)
gyp ERR! stack     at emitTwo (events.js:126:13)
gyp ERR! stack     at ChildProcess.emit (events.js:214:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:198:12)
gyp ERR! System Windows_NT 6.3.9600
gyp ERR! command "C:\\Program Files (x86)\\nodejs\\node.exe" "C:\\Program Files (x86)\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\xavier\Documents\Carestream\server\node_modules\ref
gyp ERR! node -v v8.9.4
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok
npm WARN @nestjs/common@4.6.6 requires a peer of reflect-metadata@0.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @nestjs/core@4.6.6 requires a peer of reflect-metadata@0.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @nestjs/microservices@4.6.6 requires a peer of reflect-metadata@0.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @nestjs/swagger@1.1.4 requires a peer of reflect-metadata@0.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN @nestjs/websockets@4.6.6 requires a peer of reflect-metadata@0.1.10 but none is installed. You must install peer dependencies yourself.
npm WARN nest-typescript-starter@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.1.3 (node_modules\fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"ia32"})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants