node-unix-dgram
node-unix-dgram copied to clipboard
Failing to build/install with Cannot open include file: 'unistd.h' on Windows
I'm using a project (winston-syslog) with unix-dgram as a sub-dependecy. Recently it has started failing to build with the following error. All the build tools needed should be in place, as this error started happening more or less out of nowhere..
> [email protected] install C:\project\backend\node_modules\winston-syslog\node_modules\unix-dgram
> node-gyp rebuild
C:\project\backend\node_modules\winston-syslog\node_modules\unix-dgram>if not defined npm_config_node_gyp (node "C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin\\..\..\node_modules\node-gyp\bin\node-gyp.js" rebuild ) else (node "C:\Users\AppD
ata\Roaming\npm\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.
unix_dgram.cc
win_delay_load_hook.cc
c:\project\backend\node_modules\winston-syslog\node_modules\unix-dgram\src\unix_dgram.cc(9): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory [C:\project\backend\node_modules\winston-syslog\node_modules\unix-dgram\build\unix_dgram.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Users\AppData\Roaming\npm\node_modules\npm\node_modules\node-gyp\lib\build.js:194:23)
gyp ERR! stack at ChildProcess.emit (events.js:223:5)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
gyp ERR! System Windows_NT 10.0.17134
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Users\\AppData\\Roaming\\npm\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\git\boa\corniche-boa\backend\node_modules\winston-syslog\node_modules\unix-dgram
gyp ERR! node -v v12.14.1
gyp ERR! node-gyp -v v5.0.5
gyp ERR! not ok
This is on a Windows 10 system. Installing unix-dgram directly (npm install unix-dgram) does not work either.
My hypothesis is that there's something in your environment that makes node-gyp (the build tool) think it's building for a UNIX system. It's supposed to build win_dummy.cc instead of unix_dgram.cc; there's a OS=="win"
guard in binding.gyp to that effect.
What might work is node-gyp rebuild -- -DOS=win
, although I don't know how you'd pass that through npm.
I get the exact same error. I tried installing winston-syslog on windows 10 and get:
$ npm i winston-syslog
> [email protected] install C:\Users\Me\Projects\Project\node_modules\unix-dgram
> node-gyp rebuild
C:\Users\Me\Projects\Project\node_modules\unix-dgram>if not defined npm_config_node_gyp (node "C:\Program Files\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\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.
unix_dgram.cc
win_delay_load_hook.cc
C:\Users\Me\Projects\Project\node_modules\unix-dgram\src\unix_dgram.cc(9): fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory [C:\Users\Me\Projects\Project\node_modules\unix-dgram\build\unix_dgram.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Me\Projects\Project\node_modules\unix-dgram
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
...
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules\unix-dgram):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] install: `node-gyp rebuild`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1
After the install, since it skipped unix-dgram "optional dependency", I tried running the file with require('winston-syslog')
and i got:
ERROR in ./node_modules/winston-syslog/lib/winston-syslog.js
Module not found: Error: Can't resolve 'unix-dgram' in 'C:\Users\Me\projects\project\node_modules\winston-syslog\lib'
I tried on my coworkers laptop, and he received the same error.
Please let me know if you need any more info, I will gladly provide and test things out :)
@Kresten In your case it's because you're installing v2.0.3 but it's only 2.0.4 that has the win32 stub code.
winston-syslog loads unix-dgram lazily but keep in mind that unix-dgram doesn't actually work on Windows (it's a stub, after all) so it's not like it's a useful combination. Plain UDP-over-IP should work though.
Thank you for the quick reply! I installed the newest unix-dgram and got
$ npm i unix-dgram
> [email protected] install C:\Users\Me\Projects\Project\node_modules\winston-syslog\node_modules\unix-dgram
> node-gyp rebuild
C:\Users\Me\Projects\Project\node_modules\winston-syslog\node_modules\unix-dgram>
if not defined npm_config_node_gyp (node "C:\Program Files\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\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.
unix_dgram.cc
win_delay_load_hook.cc
C:\Users\Me\Projects\Project\node_modules\winston-syslog\node_modules\unix-dgram\src\unix_dgram.cc(9):
fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory [C:\Users\Me\Projects\Project\node_modules\winston-syslog\node_modules\unix-dgram\build\unix_dgram.vcxproj]
gyp ERR! build error
gyp ERR! stack Error: `C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe` failed with exit code: 1
gyp ERR! stack at ChildProcess.onExit (C:\Program Files\nodejs\node_modules\npm\node_modules\node-gyp\lib\build.js:262:23)
gyp ERR! stack at ChildProcess.emit (events.js:198:13)
gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:248:12)
gyp ERR! System Windows_NT 10.0.18362
gyp ERR! command "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\node_modules\\node-gyp\\bin\\node-gyp.js" "rebuild"
gyp ERR! cwd C:\Users\Me\Projects\Project\node_modules\winston-syslog\node_modules\unix-dgram
gyp ERR! node -v v10.16.3
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
> [email protected] install C:\Users\Me\Projects\Project\node_modules\unix-dgram
> node-gyp rebuild
C:\Users\Me\Projects\Project\node_modules\unix-dgram>
if not defined npm_config_node_gyp (node "C:\Program Files\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\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.
win_dummy.cc
win_delay_load_hook.cc
Creating library C:\Users\Me\Projects\Project\node_modules\unix-dgram\build\Release\unix_dgram.lib and object C:\Users\Me\Projects\Project\node_modules\unix-dgram\build\Releas e\unix_dgram.exp
Generating code
All 3 functions were compiled because no usable IPDB/IOBJ from previous compilation was found.
Finished generating code
unix_dgram.vcxproj -> C:\Users\Me\Projects\Project\node_modules\unix-dgram\build\Release\\unix_dgram.node
I hope the first fail is intended to swap over to the dummy build :) The file runs fine now. I'm only using the Syslog connection in production to connect to papertrail, since winston does not have an up-to-date papertrail transport. Thanks again!