Install node-serialport module on arm-linux - node.js

I have been using node-serialport on my linux X86 machine and it works great. Now I am trying to install node-serialport on an embedded platform running arm linux. I managed to cross compile the node itself and able to run node/npm on the target platform.
However, simply running npm install serialport does not work:
binary not available for your platform
and then npm launches the build using node-gyp. Unfortunately the build requires Python which is not available on my embedded platform (tried to cross compile python without success :( )
Can anyone please help me to cross-compile serial port on my linux machine? I have tried a lot of methods on the web but all of them failed for one reason or the other

I managed to do the cross-compile serial port finally, using ugliest of methods :) Following is the method that worked:
On native x86 linux box,
cd <your work area>
Setup the cross_compiler tool environment variables:
export AR=arm-marvell-linux-gnueabi-ar
export CC=arm-marvell-linux-gnueabi-gcc
export CXX=arm-marvell-linux-gnueabi-g++
export LINK=arm-marvell-linux-gnueabi-g++
export npm_config_arch=arm
export npm_config_nodedir=/home/ysoni/node
Now run npm install. Please note that since npm install insisted that I should compile 64bit package,so I had to provide manually --package_name, --hosted_path etc. I got those params from serialport website.
npm install serialport --arch=x64 --target_arch=arm --remote_path=./serialport/v1.4.0/Release/ --package_name=node-v11-linux-ia32.tar.gz --staged_tarball=build/stage/serialport/v1.4.0/Release/node-v11-linux-ia32.tar.gz --hosted_path=https://node-serialport.s3.amazonaws.com/serialport/v1.4.0/Release/ --hosted_tarball=https://node-serialport.s3.amazonaws.com/serialport/v1.4.0/Release/node-v11-linux-ia32.tar.gz
A node_modules directory will be generated that contains .bin and serialport folders.
Now, copy the contents of node_modules to your target_platform.
I wrote a sample .js script to test if serial device could be opened. The script has to be in the same directory as node_modules.
Expectedly there has to be one last roadblock !! Weird enough, I had to do some renaming. This may not be necessary for your platform:
busybox mv node_modules/serialport/build/serialport/v1.4.2/Release/node-v11-linux-arm/ node_modules/serialport/build/serialport/v1.4.2/Release/v8-3.11-linux-arm/
In the end, I am able to open the serialport and ready contents. I really hope that there is easier way out there !
Happy hacking !!

For anybody who comes across this post (I know it's old) as of version 5.x you CAN build for ARM directly on the device, say a Raspberry Pi for example.
I just don't want developers who want to use this library to be turned off by the notion of having to cross compile because as we all know, it's a pain!

Related

How to build linux tools via MingW64 in 2021?

I'm trying to follow this example to build wget2:
https://gnutoolchains.com/building/
I've installed x86_64-8.1.0-win32-seh-rt_v6-rev0 preset (?) and first tried to build old version of wget1, but I've reached dead end. There is no way to run ./configure to create build target rules. Did I install something wrong? How I'm supposed to know what exactly is to install? Is it each new preset for each application I want to build? How I'm supposed to handle the insane list of requirements of wget2:
https://gitlab.com/gnuwget/wget2#build-requirements
And lastly - why is it so jank? Is it by design?
There is a way to run ./configure on Windows. You need MSYS2 for that, which will give you a bash shell and the tools needed by ./configure.
MSYS2 comes with a package manager (pacman) which allows you to install a more recent MinGW-w64.

Docker, AlpineLinux and Ubuntu - why does `node_modules` different

Environment
I do use CI/CD of gitlab to bundle my application.
I do use node:14-alpine as image and do run yarn to build my app.
After build is finished, I do deploy my app via rsync to the target-server, which run's ubuntu 20.04.
On this server, I do use pm2 to start the app and keep it running.
Issue
If I look into the logs, I do see an error like this:
I've searched a bit, and found that the issue might be caused of musl-dev is missing.
I've installed it at my server, and into the docker-container, but with same result.
BUT, if I do delete the node_modules directory from server, and run yarn install right at the Server, the app run like expected
Question
So why does this issue happens here? Must I have the same distribution & version of linux in my docker-container to fit all dependencies?
Don't use an Alpine image if you're deploying on Ubuntu.
So why does this issue happens here?
The fundamental C standard library implementation is different on the two (Alpine uses musl libc; Ubuntu and more or less all other distros use GNU C Library (glibc)).
Trying to move binaries (such as those that might appear in node_modules for native modules) built against one libc implementation to a system using the other will likely be painful or not work at all (as you noticed).
Must I have the same distribution & version of linux in my docker-container to fit all dependencies?
If none of the dependencies use native code, then you should be able to just move things over without issues, but otherwise it'll be easiest (e.g. considering the versions of other libraries your dependencies may link against) to just use the same version as your target OS – or, if you don't want to think about that, just deploy your application as a Docker container.
Even if the suggestion from #AKX is a good answer, I've played a bit around to figure out how to solve this special case.
Here is my solution:
install musl-dev at the server
link it to /lib
apt-get install musl-dev
ln -s /usr/lib/x86_64-linux-musl/libc.so /lib/libc.musl-x86_64.so.1
In my case it's only this single dependency which cause the trouble. If I got more of this, I will follow AKX's suggestion and choose a debian/ubuntu-like distribution to bundle it.

npm does not install any package Cannot read property 'version' of null

i'm using node v16.7.0 and npm v7.20.3. I bought new laptop(w10) and installed node but since that(almost a week), i couldn't start any node related project because i can not install any npm package. Whenever i try to 'npm install'
npm install <package>
I get the error:
npm ERR! Cannot read property 'version' of null
I dig into all around web to find a solution for this but i couldn't get one. Can someone help me with this issue this is my first question in Stackoverflow.Also if i use dual boot with Ubuntu or WSL2(Web Subsystem for Linux) will i get less errors with development tools even though i'm into web development nothing to do with kernel. Thanks...
Edit: I had spaces and non English character in my username folder in Windows so i tried changing my username and username folder and it solved my problem.(Note that changing username does not reflect to username folder you have to set extra configuration for that).
The error message means that npm is trying to read the version property of the folder's package.json file but doesn't find the file.
Check that you have a package.json file inside your folder, and see what's the value of the version property.
If you need to create a package.json file out of the box, run npm init and follow the instructions. For more information, view the npm documentation about npm init.
Also, make sure that you've installed Node correctly. It's recommended to use a Node version manager to manage your Node installations.
Also if i use dual boot with Ubuntu or WSL2(Web Subsystem for Linux)
will i get less errors with development tools even though i'm into web
development nothing to do with kernel
Yes, and dual-booting with Ubuntu would be best. Virtual machines can be slow and require additional configurations to improve performance, and a lot of issues are reported on WSL.
Most development tools work natively with Linux and therefore run better on Linux. Ultimately, it depends on what language you're developing with and what environment you're developing for.
In general, Linux will make your development experience much less of a hassle. Information, tutorials, and troubleshooting about those tools is also more easily available for Linux.
One of the best things about switching from Windows to Linux is for package management and the command-line interface. Linux makes it easy and straightforward to run commands, whereas Windows can require additional configurations, other workarounds, and intermediary steps.

Can't run NodeSchool workshops in Git Bash. "TypeError: process.stdin.setRawMode is not a function"

From the research I did for the topic, I saw some recommendations to install tty.js with npm, but it wouldn't install as well - some sort of python exe missing from the system error.
I am able to run the program from Git CMD but it is all confusing for me because I am familiar with unix based consoles :(
The way I installed node.js and npm : All was doen with the installer provided by node.js.
Any insights? Thank you in advance!
I have installed tty.js in a linux enviroment and it works great, you should some building essentials installed, such as:
gcc
g++
make
As well as Python 2.7. When installing using npm, it will look for all the dependencies and as I understand it will compile some C code that does the magic behind the scenes. I haven't tried it on Windows, but what I have seen there is the C code designed for windows, so it probably will run.
Maybe I will be of more help if you copy what you get on the npm installation.
have you tried using Git Bash? That is what I used for the most part as well and acts more unix like. If you're on a PC, an alternative is using ConEMU as they give you a shell that is unix like. Just wanted to give you some options if you're still running into trouble, I know this is super late :)

How to install spice-server correctly in CentOS 7 with the source codes?

I met a problem when I try to install QEMU with spice support.
It works well if I install spice-server with yum. In this case when I type ./configure --enable-spice in root directory of QEMU's source codes, the spice-server can be detected correctly.
But now I want to install spice-server by compiling its source codes, cause I have some work to do with it.
I tried ./configure; make; make install and ./configure --prefix=/usr; make; make install. QEMU couldn't find spice-server installed in neither way. I just got
ERROR: User requested feature spice
configure was not able to find it.
Install spice-server(>=0.12.0) and spice-protocol(>=0.12.3) devel
returned.
I don't have this problem in ubuntu, I don't know how to fix it in a CentOS server. Does anybody have a solution?
I guess you are trying to build qemu with spice from source code.
That involves many dependences and configurations.
Especially while you have system-installed 'qemu' running.
Maybe https://github.com/grizzlybears/sqb can help you.
It is a set of helper scripts to automatically do the follwing:
Install build depend.
Get code from offical repository
Get 'fedora base cloud image' as test image
Autogen/configure/build qemu with spice in local dir, touch nothing in system
5.Run test VM using our hand-made 'qemu'
Open spice console to the VM, if you have 'spice-gtk-tools' installed
You should first clone spice-protocol manually and execute ./autogen.sh && ./configure &&make &&make install and export the PKG_CONFIG_PATH export PKG_CONFIG_PATH={your pkg config path}

Resources