# Deploy failed when running balena deploy

**URL:** <https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486>\
**Category:** openBalena\
**Created:** [February 28, 2019, 12:00pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486 "2019-02-28T12:00:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![rpelletier](https://avatars.discourse-cdn.com/v4/letter/r/ecccb3/32.png) [@rpelletier](https://forums.balena.io/u/rpelletier)\
**Post date:** [February 28, 2019, 12:00pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/1 "2019-02-28T12:00:46Z")

</div>

```
balena deploy myApp--logs --source . --emulated

[Error] Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm config set unsafe-perm true && npm install --unsafe-perm --production && npm cache clean --force && npm i npm@latest -g && rm -rf /tmp/* && node_modules/.bin/electron-rebuild' returned a non-zero code: 127
```

---

<div class="post-metadata">

**Author:** ![dllb00](https://avatars.discourse-cdn.com/v4/letter/d/dec6dc/32.png) [@dllb00](https://forums.balena.io/u/dllb00)\
**Post date:** [March 25, 2019, 10:02am UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/5 "2019-03-25T10:02:44Z")

</div>

Hi everyone

I have the same problem. I followed the Getting Started Guide and double checked everything with the recently released Setup-Stream recording.  
I am trying to deploy the [Example Application](https://github.com/balena-io-playground/balena-sense-hat-python-starter) but it is crashing in the build process. I am on Arch, using the the Npm Balena-CLI.

Here is the output:

```bash
[dario@ArchDW sense-snake]$ DEBUG=1 balena deploy openBalenaTest --logs --source . --emulated
[Debug] Parsing input...
[Debug] Loading project...
[Debug] Resolving project...
[Debug] Failed to resolve project: 
[Debug] AggregateError of:
[Debug] Error: ENOENT: no such file or directory, open '/home/dario/balena/sense-snake/docker-compose.yml'
[Debug] Error: ENOENT: no such file or directory, open '/home/dario/balena/sense-snake/docker-compose.yaml'
[Info] Creating default composition with source: /home/dario/balena/sense-snake
[Debug] Creating project...
[Info] Building for armv7hf/raspberrypi3
[Build] Building services...
[Build] main Preparing...
[Info] Emulation is enabled
[Debug] Found build tasks:
[Debug] main: build [.]
[Debug] Resolving services with [raspberrypi3|armv7hf]
[Debug] Found project types:
[Debug] main: Dockerfile.template
[Debug] Prepared tasks; building...
[Build] main Step 1/13 : FROM resin/raspberrypi3-node:8.5.0 AS base
[Build] main ---> cef40d008ff1
[Build] main Step 2/13 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build] main ---> Using cache
[Build] main ---> ed0bc7ee9e48
[Build] main Step 3/13 : WORKDIR /usr/src/app
[Build] main ---> Using cache
[Build] main ---> d46077ba63f9
[Build] main Step 4/13 : COPY ["package.json","."]
[Build] main ---> Using cache
[Build] main ---> 0ccf89689b98
[Build] Built 1 service in 0:03
[Error] Deploy failed
Error: The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 139
    at Stream.<anonymous> (/usr/lib/node_modules/balena-cli/node_modules/resin-docker-build/build/builder.js:178:23)
    at Stream.stream.write (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at Stream.ondata (internal/streams/legacy.js:15:31)
    at Stream.emit (events.js:197:13)
    at Stream.EventEmitter.emit (domain.js:481:20)
    at drain (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:45:5)
    at Parser.parser.onToken (/usr/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:132:18)
    at Parser.proto.write (/usr/lib/node_modules/balena-cli/node_modules/jsonparse/jsonparse.js:135:34)
    at Stream.<anonymous> (/usr/lib/node_modules/balena-cli/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/usr/lib/node_modules/balena-cli/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:696:20)
    at IncomingMessage.emit (events.js:197:13)
    at IncomingMessage.EventEmitter.emit (domain.js:481:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at IncomingMessage.Readable.push (_stream_readable.js:224:10)
    at HTTPParser.parserOnBody (_http_common.js:126:22)
    at Socket.socketOnData (_http_client.js:447:20)
    at Socket.emit (events.js:197:13)
    at Socket.EventEmitter.emit (domain.js:481:20)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:150:17)

```

Thanks a lot  
Dario

---

<div class="post-metadata">

**Author:** ![richbayliss](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/richbayliss/32/1054_2.png) [@richbayliss](https://forums.balena.io/u/richbayliss)\
**Post date:** [March 29, 2019, 12:39pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/7 "2019-03-29T12:39:29Z")

</div>

Could you update to the latest `balena-cli` version and try again? This looks like an issue in the CLI tool rather that something openBalena specific.

---

<div class="post-metadata">

**Author:** ![dcanob](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/dcanob/32/1413_2.png) [@dcanob](https://forums.balena.io/u/dcanob)\
**Post date:** [April 9, 2019, 4:12am UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/8 "2019-04-09T04:12:07Z")

</div>

Hi, i have the same issue:

```
balena deploy MiApp --source /home/dcanob/app/main/rpi/ --deviceType raspberrypi3 --arch armv7hf --logs --emulated --build --nocache 
[Info] Compose file detected
[Info] Building for armv7hf/raspberrypi3
[Build] Building services...
[Build] app Preparing...
[Info] Emulation is enabled
[Build] app Step 1/10 : FROM resin/raspberrypi3-node:10-stretch
[Build] app ---> 881b7a980651
[Build] app Step 2/10 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build] app ---> faee13532c97
[Build] app Step 3/10 : ENV INITSYSTEM="on"
[Build] app ---> Running in 5c880e11efff
[Build] app Removing intermediate container 5c880e11efff
[Build] app ---> c18cb5949b01
[Build] app Step 4/10 : ENV UDEV="1"
[Build] app ---> Running in fda0a7ca2f4a
[Build] app Removing intermediate container fda0a7ca2f4a
[Build] app ---> 103030dc59ac
[Build] app Step 5/10 : ENV DBUS_SYSTEM_BUS_ADDRESS="unix:path=/host/run/dbus/system_bus_socket"
[Build] app ---> Running in 786425143d36
[Build] app Removing intermediate container 786425143d36
[Build] app ---> 2ad0edb37f58
[Build] app Step 6/10 : WORKDIR /usr/src/app
[Build] app ---> Running in 89d9668bfc05
[Build] app Removing intermediate container 89d9668bfc05
[Build] app ---> 49ed8bd73304
[Build] app Step 7/10 : COPY [".","./"]
[Build] app ---> 3b8aaaa88a14
[Build] app Step 8/10 : RUN ["/tmp/qemu-execve","-execve","/bin/sh","-c","JOBS=MAX npm install --unsafe-perm --production"]
[Build] app ---> Running in c0bc262eedc3
[Build] app > mi-ecobox@1.0.6 postinstall /usr/src/app
[Build] app > electron-rebuild
[Build] app internal/modules/cjs/loader.js:583
[Build] app throw err;
[Build] app ^
[Build] app Error: Cannot find module './rebuild'
[Build] app at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
[Build] app at Function.Module._load (internal/modules/cjs/loader.js:507:25)
[Build] app at Module.require (internal/modules/cjs/loader.js:637:17)
[Build] app at require (internal/modules/cjs/helpers.js:20:18)
[Build] app at Object.<anonymous> (/usr/src/app/node_modules/.bin/electron-rebuild:17:19)
[Build] app at Module._compile (internal/modules/cjs/loader.js:689:30)
[Build] app at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
[Build] app at Module.load (internal/modules/cjs/loader.js:599:32)
[Build] app at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
[Build] app at Function.Module._load (internal/modules/cjs/loader.js:530:3)
[Build] app npm ERR! code ELIFECYCLE
[Build] app npm ERR! errno 1
[Build] app npm ERR! mi-ecobox@1.0.6 postinstall: `electron-rebuild`
[Build] app npm ERR! Exit status 1
[Build] app npm ERR! 
[Build] app npm ERR! Failed at the mi-ecobox@1.0.6 postinstall script.
[Build] app npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
[Build] app npm ERR! A complete log of this run can be found in:
[Build] app npm ERR! /root/.npm/_logs/2019-04-09T04_04_15_048Z-debug.log
[Build] Built 1 service in 1:11
[Error] Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 1

Additional information may be available in debug mode. Prefix the command
line with DEBUG=1, i.e.: DEBUG=1 balena ...
If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/

```

but if run:

```
npm run rebuild

> mi-ecobox@1.0.6 rebuild /home/dcanob/ecobox/main/rpi/app
> electron-rebuild

✔ Rebuild Complete

```

and on CloudBalena this works too, my balena cli version:

balena version  
10.0.0

---

<div class="post-metadata">

**Author:** ![Ciantic](https://avatars.discourse-cdn.com/v4/letter/c/8797f3/32.png) [@Ciantic](https://forums.balena.io/u/Ciantic)\
**Post date:** [January 23, 2020, 2:14pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/9 "2020-01-23T14:14:22Z")

</div>

I have this exact same problem,

```
balena --version
11.22.0

```

here is the full output:

```
balena deploy myApp --logs --source . --emulated
[debug] original argv0="balena" argv=[/home/balena/balena-cli/balena,/snapshot/versioned-source/bin/balena,deploy,myApp,--logs,--source,.,--emulated] length=8
[Debug] Parsing input...
[Debug] Loading project...
[Debug] Resolving project...
[Debug] Failed to resolve project:
[Debug] AggregateError of:
[Debug] Error: ENOENT: no such file or directory, open '/home/balena/services/sense-snake/docker-compose.yml'
[Debug] Error: ENOENT: no such file or directory, open '/home/balena/services/sense-snake/docker-compose.yaml'
[Info] Creating default composition with source: /home/balena/services/sense-snake
[Debug] Creating project...
[Info] Building for aarch64/raspberrypi4-64
[Build] Building services...
[Build] main Preparing...
[Info] Installing qemu for aarch64 emulation...
[Info] Emulation is enabled
[Debug] Found build tasks:
[Debug] main: build [.]
[Debug] Resolving services with [raspberrypi4-64|aarch64]
[Debug] Found project types:
[Debug] main: Architecture-specific Dockerfile
[Debug] Prepared tasks; building...
[Build] main Step 1/13 : FROM balenalib/raspberrypi3-node:8-build AS base
[Build] main ---> 5ae69787fd80
[Build] main Step 2/13 : COPY [".balena/qemu-execve","/tmp/qemu-execve"]
[Build] main ---> 0832684c3ce7
[Build] main Step 3/13 : WORKDIR /usr/src/app
[Build] main ---> Running in 925c0b4a9ece
[Build] main Removing intermediate container 925c0b4a9ece
[Build] main ---> 0b622ce8d6b0
[Build] main Step 4/13 : COPY ["package.json","."]
[Build] main ---> ef30bb937c96
[Build] main Step 5/13 : RUN ["/tmp/qemu-execve","-execve","/bin/sh","-c","JOBS=MAX npm install --unsafe-perm --production"]
[Build] main ---> Running in b79ee1c08bc2
[Build] main /bin/sh: Invalid ELF image for this architecture
[Build] Built 1 service in 0:39
[Error] Deploy failed
The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 255
Error: The command '/tmp/qemu-execve -execve /bin/sh -c JOBS=MAX npm install --unsafe-perm --production' returned a non-zero code: 255
    at Stream.<anonymous> (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:178:23)
    at Stream.stream.write (/snapshot/versioned-source/node_modules/through/index.js:26:11)
    at Stream.ondata (internal/streams/legacy.js:15:31)
    at Stream.emit (events.js:189:13)
    at Stream.EventEmitter.emit (domain.js:441:20)
    at drain (/snapshot/versioned-source/node_modules/through/index.js:36:16)
    at Stream.stream.queue.stream.push (/snapshot/versioned-source/node_modules/through/index.js:45:5)
    at Parser.exports.parse.parser.onToken (/snapshot/versioned-source/node_modules/JSONStream/index.js:132:18)
    at Parser.proto.write (/snapshot/versioned-source/node_modules/jsonparse/jsonparse.js:135:34)
    at Stream.<anonymous> (/snapshot/versioned-source/node_modules/JSONStream/index.js:23:12)
    at Stream.stream.write (/snapshot/versioned-source/node_modules/through/index.js:26:11)
    at IncomingMessage.ondata (_stream_readable.js:689:20)
    at IncomingMessage.emit (events.js:189:13)
    at IncomingMessage.EventEmitter.emit (domain.js:441:20)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at IncomingMessage.Readable.push (_stream_readable.js:220:10)
    at HTTPParser.parserOnBody (_http_common.js:122:22)
    at Socket.socketOnData (_http_client.js:442:20)
    at Socket.emit (events.js:189:13)
    at Socket.EventEmitter.emit (domain.js:441:20)
    at addChunk (_stream_readable.js:284:12)
    at readableAddChunk (_stream_readable.js:265:11)
    at Socket.Readable.push (_stream_readable.js:220:10)
    at Pipe.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
    at createBuildStream.Bluebird.try.then (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:72:20)
    at Builder.createBuildStream (/snapshot/versioned-source/node_modules/resin-docker-build/build/builder.js:71:97)
    at Promise (/snapshot/versioned-source/node_modules/resin-multibuild/build/build.js:82:17)
    at Object.runBuildTask (/snapshot/versioned-source/node_modules/resin-multibuild/build/build.js:59:12)
    at /snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:157:34
    at Generator.next (<anonymous>)
    at __awaiter (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:8:71)
    at new Promise (<anonymous>)
    at __awaiter (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:4:12)
    at performSingleBuild (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:155:12)
    at Bluebird.map (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:140:20)
    at runCallback (timers.js:705:18)
    at tryOnImmediate (timers.js:676:5)
    at processImmediate (timers.js:658:5)
    at process.topLevelDomainCallback (domain.js:120:23)
    at Object.<anonymous> (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:139:39)
    at Generator.next (<anonymous>)
    at fulfilled (/snapshot/versioned-source/node_modules/resin-multibuild/build/index.js:5:58)
From previous event:
    at runCommand (/snapshot/versioned-source/build/app-capitano.js:181:14)
    at Object.exports.run (/snapshot/versioned-source/build/app-capitano.js:193:39)
    at routeCliFramework (/snapshot/versioned-source/build/preparser.js:39:79)
    at process._tickCallback (internal/process/next_tick.js:68:7)
    at Function.Module.runMain (pkg/prelude/bootstrap.js:1322:13)
    at startup (internal/bootstrap/node.js:320:19)
    at bootstrapNodeJSCore (internal/bootstrap/node.js:659:3)

If you need help, don't hesitate in contacting our support forums at
https://forums.balena.io

For CLI bug reports or feature requests, have a look at the GitHub issues or
create a new one at: https://github.com/balena-io/balena-cli/issues/
```

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [January 23, 2020, 9:00pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/10 "2020-01-23T21:00:55Z")

</div>

@Ciantic, they key error is probably:

```nohighlight
[Build] main /bin/sh: Invalid ELF image for this architecture

```

Which usually indicates a CPU architecture mismatch, such as Intel vs ARM, 32 bit vs 64 bit. It is happening at Dockerfile step 5/13, `"npm install --unsafe-perm --production"`.

Given the following output:

```nohighlight
[Info] Building for aarch64/raspberrypi4-64
[Info] Installing qemu for aarch64 emulation...
[Debug] Resolving services with [raspberrypi4-64|aarch64]

```

I gather that you project is for the RPi 4, 64 bits. The base image is however for the RPi 3, 32 bits:

```nohighlight
[Build] main Step 1/13 : FROM balenalib/raspberrypi3-node:8-build AS base

```

I don’t know if this image mismatch is necessarily a problem – I actually seem to remember that the RPi3 image works fine on the RPi4. However, it might be worth trying an RPi 4 base image, `balenalib/raspberrypi4-64-node`.

Also: `balena deploy`, as used, is building the image using your laptop (dev machine) Docker installation. To narrow down the issue, try also building without emulation on balenaCloud builders (we have ARM servers) with `balena push`, and/or building on a real RPi4 device on your desk. To test the latter, flash a [development image](https://www.balena.io/docs/reference/OS/overview/2.x/#development-vs-production-images) and place the device in [local mode](https://www.balena.io/docs/learn/develop/local-mode/), then run something like:

```nohighlight
balena deploy myApp --logs --source . --dockerPort 2375 --dockerHost 192.168.1.2

```

replacing `192.168.1.2` with your device’s IP address.

If building without emulation works, the problem may be that [QEMU](https://www.qemu.org/) is simply not up to the task; it is known to fail on some compilation tasks or other tasks, which `npm install` may be triggering. Try also running some other binary executables (other than `npm`) to rule this out – starting with something like `/bin/sh -c 'echo hello world'`.

---

<div class="post-metadata">

**Author:** ![pdcastro](https://sea2.discourse-cdn.com/balena/user_avatar/forums.balena.io/pdcastro/32/1264_2.png) [@pdcastro](https://forums.balena.io/u/pdcastro)\
**Post date:** [January 23, 2020, 9:11pm UTC](https://forums.balena.io/t/deploy-failed-when-running-balena-deploy/5486/11 "2020-01-23T21:11:32Z")

</div>

Something else that occurs to me. The installed Qemu is for `aarch64`:

```nohighlight
[Info] Installing qemu for aarch64 emulation...

```

because the application, myApp, is likely an RPi4 app, while the base image is 32 bits. Try creating an RPi3 application, myApp2, then re-run the deploy command for myApp2 instead of myApp. You will likely see a different Qemu being installed.

Similarly but alternatively, try `balena build` + `balena deploy` in separate steps, explicitly specifying the device type and architecture _ **instead of an app name** _ in the `balena build` step:

```nohighlight
balena build . --logs --emulated --deviceType raspberrypi3 --arch armv7hf
...
balena deploy myApp myImage

```

where `myImage` is the name of the image built in the first step (don’t use the `--tag` option because of [issue 825](https://github.com/balena-io/balena-cli/issues/825)).
