Search code examples
node.jswindowsatom-editornode-serialport

apm/npm serialport fail to load on Windows 10


I'm building an Atom plugin that need to use the serial port.
I've npm install --save serialport and it seem to work but when I run it on Windows 10 machine I'm getting the error #1 listed bellow.
If I delete node_modules/serialport directory and do apm install I'm getting error #2 which is a node-pre-gyn compilation error.

  1. How to fix this?
  2. Why is the difference between npm and apm?

Error #1

Error: %1 is not a valid Win32 application.
\\?\C:\Users\idoran\github\arduino\node_modules\serialport\build\Release\serialport.node
    at Error (native)
    at process.module.(anonymous function) (ELECTRON_ASAR.js:158:20)
    at process.module.(anonymous function) (ELECTRON_ASAR.js:158:20)
    at process.module.(anonymous function) [as dlopen] (ELECTRON_ASAR.js:158:20)
    at Object.Module._extensions..node (module.js:440:18)
    at Object.module.(anonymous function) [as .node] (ELECTRON_ASAR.js:158:20)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:50:27)
    at bindings (C:\Users\idoran\github\arduino\node_modules\bindings\bindings.js:76:44)
    at Object.<anonymous> (C:\Users\idoran\github\arduino\node_modules\serialport\lib\bindings.js:3:35)
    at Module._compile (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\compile-cache.js:208:21)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:50:27)
    at Object.<anonymous> (C:\Users\idoran\github\arduino\node_modules\serialport\lib\serialport.js:12:25)
    at Module._compile (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\compile-cache.js:208:21)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)
    at Module.require (module.js:367:17)
    at require (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:50:27)
    at Object.<anonymous> (C:\Users\idoran\github\arduino\lib\master.js:9:10)
    at Module._compile (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\native-compile-cache.js:103:30)
    at Object.defineProperty.value [as .js] (C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app.asar\src\compile-cache.js:208:21)
    at Module.load (module.js:357:32)
    at Function.Module._load (module.js:314:12)

Error #2

Installing modules failed
> [email protected] install C:\Users\idoran\github\arduino\node_modules\serialport
> node-pre-gyp install --fallback-to-build

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.CppBuild.targets(366,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry.  TargetFrameworkVersion or PlatformToolset may be set to an invalid version number. [C:\Users\idoran\github\arduino\node_modules\serialport\build\serialport.vcxproj]
TRACKER : error TRK0005: Failed to locate: "CL.exe". The system cannot find the file specified. [C:\Users\idoran\github\arduino\node_modules\serialport\build\serialport.vcxproj]


Failed to execute 'C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app\apm\bin\node.exe C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app\apm\bin\\..\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=C:\Users\idoran\github\arduino\node_modules\serialport\build\Release\serialport.node --module_name=serialport --module_path=C:\Users\idoran\github\arduino\node_modules\serialport\build\Release' (1)

node-pre-gyp ERR! Tried to download: https://github.com/EmergingTechnologyAdvisors/node-serialport/releases/download/4.0.1/serialport-v4.0.1-electron-v0.37-win32-ia32.tar.gz
node-pre-gyp ERR! Pre-built binaries not found for [email protected] and [email protected] (electron-v0.37 ABI) (falling back to source compile with node-gyp)
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:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app\apm\node_modules\node-gyp\lib\build.js:276:23)
gyp ERR! stack     at emitTwo (events.js:87:13)
gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:200:12)
gyp ERR! System Windows_NT 10.0.10586
gyp ERR! command "C:\\Users\\idoran\\AppData\\Local\\atom\\app-1.10.0\\resources\\app\\apm\\bin\\node.exe" "C:\\Users\\idoran\\AppData\\Local\\atom\\app-1.10.0\\resources\\app\\apm\\node_modules\\node-gyp\\bin\\node-gyp.js" "build" "--fallback-to-build" "--module=C:\\Users\\idoran\\github\\arduino\\node_modules\\serialport\\build\\Release\\serialport.node" "--module_name=serialport" "--module_path=C:\\Users\\idoran\\github\\arduino\\node_modules\\serialport\\build\\Release"
gyp ERR! cwd C:\Users\idoran\github\arduino\node_modules\serialport
gyp ERR! node -v v4.4.5
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute 'C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app\apm\bin\node.exe C:\Users\idoran\AppData\Local\atom\app-1.10.0\resources\app\apm\bin\\..\node_modules\node-gyp\bin\node-gyp.js build --fallback-to-build --module=C:\Users\idoran\github\arduino\node_modules\serialport\build\Release\serialport.node --module_name=serialport --module_path=C:\Users\idoran\github\arduino\node_modules\serialport\build\Release' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (C:\Users\idoran\github\arduino\node_modules\serialport\node_modules\node-pre-gyp\lib\util\compile.js:83:29)
node-pre-gyp ERR! stack     at emitTwo (events.js:87:13)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:172:7)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:827:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:211:5)
node-pre-gyp ERR! System Windows_NT 10.0.10586
node-pre-gyp ERR! command "C:\\Users\\idoran\\AppData\\Local\\atom\\app-1.10.0\\resources\\app\\apm\\bin\\node.exe" "C:\\Users\\idoran\\github\\arduino\\node_modules\\serialport\\node_modules\\node-pre-gyp\\bin\\node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd C:\Users\idoran\github\arduino\node_modules\serialport
node-pre-gyp ERR! node -v v4.4.5
node-pre-gyp ERR! node-pre-gyp -v v0.6.29
node-pre-gyp ERR! not ok
npm ERR! Windows_NT 10.0.10586
npm ERR! argv "C:\\Users\\idoran\\AppData\\Local\\atom\\app-1.10.0\\resources\\app\\apm\\bin\\node.exe" "C:\\Users\\idoran\\AppData\\Local\\atom\\app-1.10.0\\resources\\app\\apm\\node_modules\\npm\\bin\\npm-cli.js" "--globalconfig" "C:\\Users\\idoran\\.atom\\.apm\\.apmrc" "--userconfig" "C:\\Users\\idoran\\.atom\\.apmrc" "install" "--runtime=electron" "--target=0.37.8" "--arch=ia32" "--msvs_version=2015"
npm ERR! node v4.4.5
npm ERR! npm  v3.10.5
npm ERR! code ELIFECYCLE

npm ERR! [email protected] install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the [email protected] install script 'node-pre-gyp install --fallback-to-build'.
npm ERR! Make sure you have the latest version of node.js and npm installed.
npm ERR! If you do, this is most likely a problem with the serialport package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-pre-gyp install --fallback-to-build
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs serialport
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!     npm owner ls serialport
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     C:\Users\idoran\github\arduino\npm-debug.log

Solution

  • You can use electron-rebuild to build native modules with specific node/Atom version. This would ensure that module is built and installed at the location Atom expects it to find.

    I used this approach for using node-serialport in an Electron project.

    Edit :

    electron-rebuild depends on availability of VC++ compiler (cl.exe). Ensure that cl.exe is installed and is on path. Visual Studio does not install c++ by default, so choose vc++ as option during setup.

    https://blogs.msdn.microsoft.com/vcblog/2015/07/24/setup-changes-in-visual-studio-2015-affecting-c-developers/