英文:
How to install serial port module on Node?
问题
I have a problem installing the serial module on Node. I am using Raspbian server for orange pi zero H2.
root@OrangePI:/home/node# npm install serialport
return
npm WARN package.json one@1.0.0 No description
npm WARN package.json one@1.0.0 No repository field.
npm WARN package.json one@1.0.0 No README data
npm WARN engine serialport@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-ready@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-mock@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-byte-length@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/stream@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/bindings@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-readline@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-regex@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-delimiter@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-cctalk@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-abstract@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-abstract@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine prebuild-install@5.3.3: wanted: {"node":">=6"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine expand-template@2.0.3: wanted: {"node":">=6"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine decompress-response@4.2.1: wanted: {"node":">=8"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine mimic-response@2.0.0: wanted: {"node":">=8"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine readable-stream@3.4.0: wanted: {"node":">= 6"} (current: {"node":"4.9.1","npm":"2.15.11"})
...
> @serialport/bindings@8.0.6 install /home/node/node_modules/serialport/node_modules/@serialport/bindings > prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
/home/node/node_modules/serialport/node_modules/@serialport/bindings/node_modules/prebuild-install/node_modules/simple-get/index.js:18
const { hostname, port, protocol, auth, path } = url.parse(opts.url) // eslint-disable-line node/no-deprecated-api
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/node/node_modules/serialport/node_modules/@serialport/bindings/node_modules/prebuild-install/download.js:3:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
I have little experience in linux ... but is it my impression or is the declared constant really unnamed?
make: Entering directory
'/home/node/node_modules/serialport/node_modules/@serialport/bindings/build'
CXX(target) Release/obj.target/bindings/src/serialport.o
make: g++: Command not found
bindings.target.mk:97: recipe for target 'Release/obj.target/bindings/src/serialport.o' failed
make: *** [Release/obj.target/bindings/src/serialport.o] Error 127
make: Leaving directory '/home/node/node_modules/serialport/node_modules/@serialport/bindings/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/opt/node/lib/node_modules/npm/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:211:12)
gyp ERR! System Linux 3.4.39
gyp ERR! command "/opt/node/bin/node" "/opt/node/lib/node_modules/npm/node_modules/node- gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/node/node_modules/serialport/node_modules/@serialport/bindings
gyp ERR! node -v v4.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm ERR! Linux 3.4.39
npm ERR! argv "/opt/node/bin/node" "/opt/node/bin/npm" "install" "serialport"
npm ERR! node v
<details>
<summary>英文:</summary>
I have a problem installing the serial module on Node. I am using Raspbian server for orange pi zero H2.
root@OrangePI:/home/node# npm install serialport
return
npm WARN package.json one@1.0.0 No description
npm WARN package.json one@1.0.0 No repository field.
npm WARN package.json one@1.0.0 No README data
npm WARN engine serialport@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-ready@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-mock@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-byte-length@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/stream@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/bindings@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-readline@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-regex@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-delimiter@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/parser-cctalk@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-abstract@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine @serialport/binding-abstract@8.0.6: wanted: {"node":">=8.6.0"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine prebuild-install@5.3.3: wanted: {"node":">=6"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine expand-template@2.0.3: wanted: {"node":">=6"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine decompress-response@4.2.1: wanted: {"node":">=8"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine mimic-response@2.0.0: wanted: {"node":">=8"} (current: {"node":"4.9.1","npm":"2.15.11"})
npm WARN engine readable-stream@3.4.0: wanted: {"node":">= 6"} (current: {"node":"4.9.1","npm":"2.15.11"})
...
> @serialport/bindings@8.0.6 install /home/node/node_modules/serialport/node_modules/@serialport/bindings > prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
/home/node/node_modules/serialport/node_modules/@serialport/bindings/node_modules/prebuild-install/node_modules/simple-get/index.js:18
const { hostname, port, protocol, auth, path } = url.parse(opts.url) // eslint-disable-line node/no-deprecated-api
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Module.require (module.js:353:17)
at require (internal/module.js:12:17)
at Object.<anonymous> (/home/node/node_modules/serialport/node_modules/@serialport/bindings/node_modules/prebuild-install/download.js:3:11)
at Module._compile (module.js:409:26)
at Object.Module._extensions..js (module.js:416:10)
I have little experience in linux ... but is it my impression or is the declared constant really unnamed?
make: Entering directory
'/home/node/node_modules/serialport/node_modules/@serialport/bindings/build'
CXX(target) Release/obj.target/bindings/src/serialport.o
make: g++: Command not found
bindings.target.mk:97: recipe for target 'Release/obj.target/bindings/src/serialport.o' failed
make: *** [Release/obj.target/bindings/src/serialport.o] Error 127
make: Leaving directory '/home/node/node_modules/serialport/node_modules/@serialport/bindings/build'
gyp ERR! build error
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack at ChildProcess.onExit (/opt/node/lib/node_modules/npm/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:211:12)
gyp ERR! System Linux 3.4.39
gyp ERR! command "/opt/node/bin/node" "/opt/node/lib/node_modules/npm/node_modules/node- gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /home/node/node_modules/serialport/node_modules/@serialport/bindings
gyp ERR! node -v v4.9.1
gyp ERR! node-gyp -v v3.4.0
gyp ERR! not ok
npm ERR! Linux 3.4.39
npm ERR! argv "/opt/node/bin/node" "/opt/node/bin/npm" "install" "serialport"
npm ERR! node v4.9.1
npm ERR! npm v2.15.11
npm ERR! code ELIFECYCLE
npm ERR! @serialport/bindings@8.0.6 install: `prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @serialport/bindings@8.0.6 install script 'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild'.
npm ERR! This is most likely a problem with the @serialport/bindings package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs @serialport/bindings
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls @serialport/bindings
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /home/node/npm-debug.log
last part of the log file
5807 info install prebuild-install@5.3.3
5808 info postinstall prebuild-install@5.3.3
5809 verbose unlock done using /root/.npm/_locks/prebuild-install-da7fa1c0b3187458.lock for /home/node/node_modules/serialport/node_modules/@serialport/bindings/node_modules/prebuild-install
5810 verbose about to build /home/node/node_modules/serialport/node_modules/@serialport/bindings
5811 info build /home/node/node_modules/serialport/node_modules/@serialport/bindings
5812 info linkStuff @serialport/bindings@8.0.6
5813 silly linkStuff @serialport/bindings@8.0.6 has /home/node/node_modules/serialport/node_modules as its parent node_modules
5814 verbose linkBins @serialport/bindings@8.0.6
5815 verbose linkMans @serialport/bindings@8.0.6
5816 verbose rebuildBundles @serialport/bindings@8.0.6
5817 verbose rebuildBundles [ '.bin', '@serialport', 'bindings', 'nan', 'prebuild-install' ]
5818 info install @serialport/bindings@8.0.6
5819 verbose unsafe-perm in lifecycle true
5820 info @serialport/bindings@8.0.6 Failed to exec install script
5821 verbose unlock done using /root/.npm/_locks/serialport-bindings-291f31ff80e6691d.lock for /home/node/node_modules/serialport/node_modules/@serialport/bindings
5822 verbose about to build /home/node/node_modules/serialport
5823 verbose unlock done using /root/.npm/_locks/serialport-a4250c37e3372508.lock for /home/node/node_modules/serialport
5824 verbose stack Error: @serialport/bindings@8.0.6 install: `prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild`
5824 verbose stack Exit status 1
5824 verbose stack at EventEmitter.<anonymous> (/opt/node/lib/node_modules/npm/lib/utils/lifecycle.js:217:16)
5824 verbose stack at emitTwo (events.js:87:13)
5824 verbose stack at EventEmitter.emit (events.js:172:7)
5824 verbose stack at ChildProcess.<anonymous> (/opt/node/lib/node_modules/npm/lib/utils/spawn.js:24:14)
5824 verbose stack at emitTwo (events.js:87:13)
5824 verbose stack at ChildProcess.emit (events.js:172:7)
5824 verbose stack at maybeClose (internal/child_process.js:862:16)
5824 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:222:5)
5825 verbose pkgid @serialport/bindings@8.0.6
5826 verbose cwd /home/node
5827 error Linux 3.4.39
5828 error argv "/opt/node/bin/node" "/opt/node/bin/npm" "install" "--unsafe-perm" "serialport"
5829 error node v4.9.1
5830 error npm v2.15.11
5831 error code ELIFECYCLE
5832 error @serialport/bindings@8.0.6 install: `prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild`
5832 error Exit status 1
5833 error Failed at the @serialport/bindings@8.0.6 install script 'prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild'.
5833 error This is most likely a problem with the @serialport/bindings package,
5833 error not with npm itself.
5833 error Tell the author that this fails on your system:
5833 error prebuild-install --tag-prefix @serialport/bindings@ || node-gyp rebuild
5833 error You can get information on how to open an issue for this project with:
5833 error npm bugs @serialport/bindings
5833 error Or if that isn't available, you can get their info via:
5833 error
5833 error npm owner ls @serialport/bindings
5833 error There is likely additional logging output above.
5834 verbose exit [ 1, true ]
make by default is not installed in this version,
any suggestions are welcome, thanks for your time.
</details>
# 答案1
**得分**: 2
Update your nodejs
> npm警告engine serialport@8.0.6:期望:{"node":">=8.6.0"}(当前版本:{"node":"4.9.1","npm":"2.15.11"})
你当前的版本不支持ES6语法
> ```
const { hostname, port, protocol, auth, path } = url.parse(opts.url)
> ^
语法错误:意外的标记{
<details>
<summary>英文:</summary>
Update your nodejs
> npm WARN engine serialport@8.0.6: wanted: {"node":">=**8.6.0**"} (current: {"node":"**4.9.1**","npm":"2.15.11"})
your current version do not understand ES6 syntax
> ```
const { hostname, port, protocol, auth, path } = url.parse(opts.url)
> ^
SyntaxError: Unexpected token {
</details>
# 答案2
**得分**: 2
我遇到了类似的问题。我的解决方案是:我更加具体地指定了我使用的Node.js版本。我当时使用的是最新版本(写下这些文字时是13.8),与楼主遇到了相同的问题。
所以我安装了nvm,并开始使用它来选择我的Node.js版本。
$ nvm install --lts
$ nvm use --lts
现在使用的是Node.js v12.16.0。
当前的长期支持版本(写下这些文字时)是12.6。我重新运行了`npm install`来安装应用程序,之后串口通信没有出现任何问题。理论上,我可以不断地使用nvm来安装不同版本的Node.js,直到找到一个能正常工作的版本。
<details>
<summary>英文:</summary>
I had a similar problem. My solution: I got more specific about which version of nodejs I was using. I had the latest release (at this writing) 13.8 and I had the same problems as the OP.
So I installed nvm and started using it to pick my nodejs.
$ nvm install --lts
$ nvm use --lts
Now using node v12.16.0
The current Long Term Support version (at this writing) is 12.6. I redid `npm install` for the app and after that I had no problems with the serial port. Theoretically, I could have kept nvm'installing different version of nodejs until I got the one that worked.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论