Error in heroku buildpack when using cache

I was able to deploy my first fly app yesterday, when trying to redeploy it today, after making some changes to the source code, I start to get a new error:

flyctl deploy --local-only
==> Verifying app config
--> Verified app config
==> Building image
==> Building image with Buildpacks
--> docker host: 20.10.13 linux aarch64
20: Pulling from heroku/buildpacks
Digest: sha256:c94e1868bc1410518e0d299e6aab07dc2bf91b3fffa2c78115e4293d00d840b7
Status: Image is up to date for heroku/buildpacks:20
20: Pulling from heroku/pack
Digest: sha256:4b028636c6d212bbba0e8f1a5b4a9097c4a27ba8b2b85d970895e2a639d552d6
Status: Image is up to date for heroku/pack:20
heroku/nodejs-engine 0.8.2
heroku/nodejs-yarn   0.2.2
heroku/procfile      0.6.2
Restoring metadata for "heroku/nodejs-engine:dist" from app image
Restoring metadata for "heroku/nodejs-engine:web_env" from app image
Restoring metadata for "heroku/nodejs-yarn:node_modules" from cache
Restoring metadata for "heroku/nodejs-yarn:toolbox" from cache
Restoring data for "heroku/nodejs-engine:dist" from cache
Restoring data for "heroku/nodejs-yarn:node_modules" from cache
Restoring data for "heroku/nodejs-yarn:toolbox" from cache

[Heroku Node.js Engine Buildpack]

[Checking Node.js version]
Detected Node.js version range: >=17.4.0
Resolved Node.js version: 17.8.0

[Installing Node.js distribution]
Reusing Node.js 17.8.0
[INFO] Installing toolbox
[INFO] Installing yarn

changed 1 package, and audited 2 packages in 7s

found 0 vulnerabilities
npm notice 
npm notice New minor version of npm available! 8.5.5 -> 8.7.0
npm notice Changelog: <>
npm notice Run `npm install -g npm@8.7.0` to update!
npm notice 
---> Installing node modules from ./yarn.lock
yarn install v1.22.18
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
Done in 41.67s.
yarn run v1.22.18
$ tsc
Done in 13.15s.
ERROR: failed to build: toml: line 7: Key 'metadata' has already been defined.
Error failed to fetch an image or build from source: executing lifecycle: failed with status code: 52

Reverted back to the previous commit, same build error. After reading a bit in the heroku buildpack code i noticed that the issue might be that some output file might be contained in the build cache and appended to again, causing the duplicate key by virtue of combining the output from my previous (cached) build with the output of my new build. Then tried building without cache, and it works.

flyctl deploy --local-only --no-cache for those who have the same issue.


CC: Fly Team: I also ran into this issue today, it’s still a problem.

The --local-only --no-cache flags also “solved” it.

1 Like

I’m having this issue as well both locally and from a GitHub action. --no-cache was the workaround in both cases.

I cannot apply this circumvention. --no-cache makes no difference, while --local-only says

WARN Error connecting to local docker daemon: error during connect: This error may indicate that the docker daemon is not running.: Get “http://%2F%2F.%2Fpipe%2Fdocker_engine/_ping”: open //./pipe/docker_engine: The system cannot find the file specified.

--local-only would require Docker to be running on your local machine.

If you’re using the remote builder with --no-cache and still having a problem, try deleting the builder from your account. If I try to build too many times at once (from GitHub Actions, mostly) I’ll run into issues with “volume in use” since the builder is already doing something. Trashing the remote builder forces creation of a new one and can help track down issues.