Balena CLI & PNPM file not found issues

Hey,

I wish an happy new year to the balena team!

When i use balena cli in my pnpm monorepo i get an error message.
if i use balena deploy or balena build it gives me the same error.
Even if i try to push to a raspberrypi4 its the same.

[debug] new argv=[/usr/local/lib/balena-cli/bin/node,/usr/local/lib/balena-cli/bin/run,build,-A,aarch64,-d,raspberrypi4-64,.] length=8
[debug] Deprecation check: 1.99573 days since last npm registry query for next major version release date.
[debug] Will not query the registry again until at least 7 days have passed.
[Debug]   Parsing input...
[Debug]   Loading project...
[Debug]   Resolving project...
[Debug]   docker-compose.yml file found at "/Users/xyz/abc/NusterKit"
[Debug]   Creating project...
[Build]   Building services...
[Build]   mongodb        Preparing...
[Build]   nuster-turbine Preparing...
[Build]   nuster-desktop Preparing...
[Build]   weston         Preparing...
[Build]   wpe            Preparing...
[Build]   proxy          Preparing...
[Build]   wifi-connect   Preparing...
[Info]    Building for aarch64/raspberrypi4-64
[Info]    Docker Desktop detected (daemon architecture: "aarch64")
[Info]      Docker itself will determine and enable architecture emulation if required,
[Info]      without balena-cli intervention and regardless of the --emulated option.
[debug] Event tracking error: Timeout awaiting 'response' for 0ms
[Build]   Built 7 services in 0 seconds
[Error]   Build failed.
No such file or directory: /Users/xyz/abc/NusterKit/node_modules/.pnpm/esbuild@0.16.10/node_modules/@esbuild/android-arm

Error: ENOENT: no such file or directory, stat '/Users/xyz/abc/NusterKit/node_modules/.pnpm/esbuild@0.16.10/node_modules/@esbuild/android-arm'

For further help or support, visit:
https://www.balena.io/docs/reference/balena-cli/#support-faq-and-troubleshooting

Im using a M1 Pro macbook pro as my dev machine.

I tried uninstalling balena-cli and updating it without any success.
If someone has an idea of what i should try next, it would be awersome.

have a nice day :slight_smile:

Can you share the command you are using to start the build. If you are using --emulated you might try to run it without it as M1 is an arm processor.

Running:

  • balena build -A aarch64 -d raspberrypi4-64 .
  • balena push <raspberrypi4IP>
  • balena build -f <FleetName>
  • balena deploy

Gives the same error message. I event tried all the commands with the --emulated flag.

Hi @kworz,

Something is bothering me in the logs. You have an error No such file or directory: /Users/xyz/abc/NusterKit/node_modules...

but /Users/xyz/abc... is a MacOS path, your build should run inside a docker container so a linux environment (i’m not event taking into account the android-arm part which is non-sense as you will be targeting linux).

If there is no reference inside your project to absolute path (you should never do this, it makes you project painful to build on any other machine), that is probably due to a symbolic link or node configuration failing at some point.

A nice practice for node projects is to delete the “node_modules” folder before building your project, and then, in your Dockerfile do the npm i to download the correct version of the libraries for you target system.

Let us know if it helps,

Hi @wolvi-lataniere,

The MacOS path might be related to how PNPM uses /node_modules/ with symlinks inside.
I just checked the pnpm documentation and they mentions about pnpm fetch which should solve this issue.

i do not thinks deleting node_modules before the build process helps because i’m using a .dockerignore file.

I going to investigate in this direction, and post an update here.

@wolvi-lataniere,

To update: I tried swithing to pnpm fetch as a fallback. The behavior is the same., just to be sure i tried building the project using docker-compose and it successfully built. I have no idea what is going on with balena-cli…

I also removed from my docker-compose.yml services that relied on nodeJS to be sure that npm/pnpm would never be called, and it did not work too.

i am wondering if balena-cli is clashing with my pnpm installation.
To be clear, i can still use the github action balena-deploy to build my project and it works.

It’s quite annoying because i cant develop locally.

I you have any idea of what i should try next, it would be awersome.

I see @kworz ,

you are probably right about the symlinks, this was also my initial guess, and I think it can still stand somehow bypassing the .dockerignore file and messing with the generation.

It might also fail due to caching (you can run balena build with the --nocache option to prevent reusing cached build/config).

Do you keep having the same error message?

What bothers me is we don’t see the usual Step 1/X indicating the Dockerfile starts to be parsed. This can also come from the fact that on MacOS, docker is running into a virual linux environment, and balena-cli/docker might try to copy it’s context (the current folder) to this environment before starting the build. As a test you can move your node_modules folder to a parent directory if you don’t want to remove it and try to rebuild from there (as it seems the incriminated symlinks come from this folder).

Let me know if it helps.

Hey @wolvi-lataniere,

Seems that deleting /node_modules and running pnpm install managed to get this working again !
I have no clue on what was the real problem on this.

[Build]   mongodb        Image size: 349.22 MB
[Build]   nuster-turbine Image size: 750.25 MB
[Build]   nuster-desktop Image size: 630.69 MB
[Build]   weston         Image size: 60.70 MB
[Build]   wpe            Image size: 273.01 MB
[Build]   proxy          Image size: 128.28 MB
[Build]   wifi-connect   Image size: 12.96 MB
[Build]   Built 7 services in 7:02
[Success] Build succeeded!

It took a bit of time for a native build but i will take it.

Thank you for this simple trick :slight_smile: