Local mode Node Error

I have enabled local mode from the dashboard. Then ran sudo resin local push to push code locally to the device. Local mode was functioning perfect earlier in the day and I have tried a few things to fix this error but I have reached a dead end. If I push to resin master it the update and application runs ok. Any debugging tips would be greatly appreciated.

Here are the logs:

rdt push completed successfully!

  • Streaming application logs…
    sleep: using busy loop fallback
    throw e

Error: /usr/src/app/node_modules/ioctl/build/Release/ioctl.node: invalid ELF header
at Object.Module._extensions…node (module.js:653:18)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at bindings (/usr/src/app/node_modules/bindings/bindings.js:81:44)
at Object. (/usr/src/app/node_modules/ioctl/index.js:1:94)
at Module._compile (module.js:624:30)
at Object.Module._extensions…js (module.js:635:10)
at Module.load (module.js:545:32)
at tryModuleLoad (module.js:508:12)
at Function.Module._load (module.js:500:3)
at Module.require (module.js:568:17)
at require (internal/module.js:11:18)
at Object. (/usr/src/app/node_modules/sense-hat-led/index.js:10:15)

just to make it clear, you were performing “resin local push” and was working ok, but later on you started getting that error?
Have you changed your development environment?

Yes that is correct. Earlier in the day i was using local mode then later in the day started a new project folder and was able to push to resin master and build fine but local threw that error.

I did some research on that node package ioctl and there was a known error for building in environment and then moving to another. So i deleted everything on resin and on my computer tried again fresh and same error.

That lead me on some research about a npm packages called sleep that may sometimes get stuck in a infinite loop and may throw an error if it tries to start a new process and the other is still running ao i killed all terminals and processes and still the same error.

So the last straw because i wanted to use local mode was switch to use python which i uncovered many bugs with the python base images but that another ticket. However after some effort was able to get the project pushed using local mode via python but still getting errors via node.

So im fairly deep in the weeds with no idea how to debug and fix the error in Node project.

Hey @elrickvm,

Can you try do the local push with the --force-build flag.

I’m wondering if it’s a problem with ‘rsync’, because if Dockerfile or any file in the ‘build-triggers’ list is changed, a new container will be built and run on your device. If not, changes will simply be synced with rsync into the application container.

Huh…I will try that! I tried it with -f but not --force-build. I will try it a little later. Is there a way to remove container images from resin that i may have built in the past or no?

I just tried to run sudo resin local push --force-build and get the same error with node.

Do you have the latest version of resin cli?

Also, what is the node version you have?
Can you try npm install bcrypt in your environment?

I have the resin-cli version 6.8.0 and i have tried several version of node 7.8.0, 7.9.0, 8.0, 8.1.3, 8.7.0, 8.8.1. Lastly, I have installed the bcrypt and still the same error.

Ok so the only way that i was able to get Local Mode to work with Node is I had to delete my node_modules folder in my local repo rm -rf node_modules, do a npm install npm install sleep --save and then do sudo resin local push --force-build.

Problem is this is not reliable as it doesn’t work all the time.

Another thing that i notice while debugging this is that sometime the .resin-sync.yaml does not write the environment and ignore section in the file. Not sure if that is a problem as well. Hope all my issue reports is helping. Local mode is a killer feature!!!

@pimterry @hedss do you know why this would happen?

Hey @elrickvm,

The short answer is that it’s expected behaviour, but I agree that this is something that should be documented better. I’ve already filed a meaty issue in resin local push: Improve UX and/or document 'environment' and 'ignore' CLI option saving logic · Issue #708 · balena-io/balena-cli · GitHub where I explain the current behaviour and how we could improve the UX. The TL;D;R is that , environment is only saved when resin local push (re)builds the container and ignore is only saved when resin local push remote-syncs the local files instead.

Best, Kostas

Ok cool. Thank you for the link ill check it out.

@elrickvm how’s the situation now? I’m not certain which parts of this thread, if any, are still causing problems.

The situation is one that i know how to fix now. So, if local mode fails I can get it back working. Thank you for making sure i was good. I really appreciate all of the feedback giving in this entire thread from everyone!

1 Like

Hi @elrickvm.

I am getting started with balena and Nodejs in local mode, and I’m getting the invalid ELF header error as well. Do you mind sharing your dockerfile and other details about your setup?

On this page about developing docker files, there is a quote:

These are shell commands that are run within the container on the build server which are configured such that dependencies are resolved for the target architecture not the build server’s - this can be very useful for deploying non-javascript code or fulfilling package dependencies that your node code might require.

As I can tell the invalid ELF header error is exactly related to the architecture not matching. I just don’t understand how running the installs in a bash script is different from running them in the Dockerfile with RUN.

To close the loop on this issue: there are some further details specifying the reasons why this error occurs with balena (nee resin) local push here.

tl;dr - The local node_modules with the development machine architecture binaries were being copied to the device and used instead of device native ones.