node使用node-gyp编译的插件在开发和打包,会遇到很多不同的问题。往往搞到我们无从下手。以下是我的一些心得,希望适合您。

Error:

1. was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 64

stderr:  D:\yiz\work\argos-2020-02-05\programs\release\
index.js:238 stderr:  win32\programs\server\node_modules\fibers\future.js:280
						throw(ex);
						^

Error: The module '\\?\D:\yiz\work\argos-2020-02-05\programs\release\win32\programs\server\npm\node_modules\usb\build\Release\usb_bindings.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 57. This version of Node.js requires
NODE_MODULE_VERSION 64. Please try re-compiling or re-installing
the module (for instance, using `npm rebuild` or `npm install`).

2. fibers\future.js usb_bindings.node is not a valid Win32 application.

stderr:  D:\yiz\work\argos-2020-02-05\programs\re
index.js:238 stderr:  lease\win32\programs\server\node_modules\fibers\future.js:280
						throw(ex);
						^

Error: \\?\D:\yiz\work\argos-2020-02-05\programs\release\win32\programs\server\npm\node_modules\usb\build\Release\usb_bindings.node is not a valid Win32 application.

\\?\D:\yiz\work\argos-2020-02-05\programs\release\win32\programs\server\npm\node_modules\usb\build\Release\usb_bindings.node

可能的解决方法:

一、安装node模块时,注意打印信息内容:

1.普通node环境安装usb模块

npm i usb命令:

PS D:\yiz\work\argos-2020-02-05> npm i usb

> usb@1.6.2 install D:\yiz\work\argos-2020-02-05\node_modules\usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.3
prebuild-install info looking for cached prebuild @ C:\Users\seeing\AppData\Roaming\npm-cache\_prebuilds\7ae3e9-usb-v1.6.2-node-**v64-win32**-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\seeing\AppData\Roaming\npm-cache\_prebuilds\7ae3e9-usb-v1.6.2-node-v64-win32-x64.tar.gz
prebuild-install info unpack resolved to D:\yiz\work\argos-2020-02-05\node_modules\usb\build\Release\usb_bindings.node
prebuild-install info unpack required D:\yiz\work\argos-2020-02-05\node_modules\usb\build\Release\usb_bindings.node successfully
prebuild-install info install Successfully installed prebuilt binary!
npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install
peer dependencies yourself.
npm WARN eslint-plugin-vue@5.2.3 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN vue-eslint-parser@5.0.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.1 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.1 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN The package nw-builder is included as both a dev and production dependency.

+ usb@1.6.2
added 21 packages from 16 contributors and updated 1 package in 7.143s
2.meteor环境内安装usb模块

meteor npm i usb命令:

PS D:\yiz\work\argos-2020-02-05> meteor npm i usb

> usb@1.6.2 install D:\yiz\work\argos-2020-02-05\node_modules\usb
> prebuild-install --verbose || node-gyp rebuild

prebuild-install info begin Prebuild-install version 5.3.3
prebuild-install info looking for cached prebuild @ C:\Users\seeing\AppData\Roaming\npm-cache\_prebuilds\997bd6-usb-v1.6.2-node-**v57-win32**-x64.tar.gz
prebuild-install info found cached prebuild
prebuild-install info unpacking @ C:\Users\seeing\AppData\Roaming\npm-cache\_prebuilds\997bd6-usb-v1.6.2-node-v57-win32-x64.tar.gz
prebuild-install info unpack resolved to D:\yiz\work\argos-2020-02-05\node_modules\usb\build\Release\usb_bindings.node
prebuild-install info unpack required D:\yiz\work\argos-2020-02-05\node_modules\usb\build\Release\usb_bindings.node successfully
prebuild-install info install Successfully installed prebuilt binary!
npm WARN acorn-dynamic-import@4.0.0 requires a peer of acorn@^6.0.0 but none is installed. You must install
peer dependencies yourself.
npm WARN eslint-plugin-vue@5.2.3 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN vue-eslint-parser@5.0.0 requires a peer of eslint@^5.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.1 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.1 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN The package nw-builder is included as both a dev and production dependency.

+ usb@1.6.2
added 21 packages from 16 contributors and updated 1 package in 6.382s

**区别:**生成的usb包一个是v64,另一个是v57。
**原因:**可能meteor npm在安装的时候做了一些处理,或者环境不一样。

二、对比开发环境和打包后的生产环境node版本异同:

因为有时候我们开发的环境里面的各种软件,跟生产环境的软件版本不同,会造成各种问题。所以我们要理清软件运行要依赖的各种环境是否一致。
如何查看node环境,可以在cmd(命令提示符)中:
输入:node进入node环境,
然后输入:process查看所有信息。
在这里插入图片描述

相关解决方案

https://segmentfault.com/a/1190000016565228?utm_source=tag-newest

https://www.cnblogs.com/wangyuxue/p/11218113.html

https://blog.csdn.net/you23hai45/article/details/86236769

欢迎大神留言讨论!

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐