0

我正在构建一个需要使用串行端口的 Atom 插件。
我已经npm install --save serialport并且它似乎可以工作,但是当我在 Windows 10 机器上运行它时,我得到了下面列出的错误 #1。
如果我删除node_modules/serialport目录并apm install收到错误 #2,这是一个节点预妇科编译错误。

  1. 如何解决这个问题?
  2. npm为什么和有区别apm

错误 #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)

错误 #2

Installing modules failed
> serialport@4.0.1 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 serialport@4.0.1 and electron@0.37.8 (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! serialport@4.0.1 install: `node-pre-gyp install --fallback-to-build`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the serialport@4.0.1 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
4

1 回答 1

1

您可以使用electron-rebuild构建具有特定节点/Atom 版本的本机模块。这将确保在 Atom 期望它找到的位置构建和安装模块。

我使用这种方法在 Electron 项目中使用 node-serialport。

编辑 :

electron-rebuild 取决于 VC++ 编译器 (cl.exe) 的可用性。确保 cl.exe 已安装并且在路径上。Visual Studio 默认不安装 c++,因此在安装过程中选择 vc++ 作为选项。

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

于 2016-09-05T05:47:14.153 回答