Failed to build: Key 'metadata' has already been defined

Hi folks! I started getting the following error this morning for the first time: ERROR: failed to build: toml: line 7: Key 'metadata' has already been defined. How can I debug this?

Here’s the full build log:

❯ flyctl deploy --app XXX --strategy immediate
==> 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:fbdf9574e08ea2ebdde8062da6a86d33fd42c5576e6f43f93a7c6fe2e4104b9a
Status: Image is up to date for heroku/buildpacks:20
20-cnb: Pulling from heroku/heroku
Digest: sha256:5cfc72ccdb10b0c0e877f1baa5d336042a134a1f50ff2aec11a8644c464e5113
Status: Image is up to date for heroku/heroku:20-cnb
===> DETECTING
2 of 3 buildpacks participating
heroku/nodejs-engine 0.8.6
heroku/nodejs-yarn   0.2.3
===> ANALYZING
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
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
===> BUILDING

[Heroku Node.js Engine Buildpack]

[Checking Node.js version]
Detected Node.js version range: >=16.15.0 <16.16.0-0
Resolved Node.js version: 16.15.1

[Installing Node.js distribution]
Downloading Node.js 16.15.1
Extracting Node.js 16.15.1
Installing Node.js 16.15.1
[INFO] Installing toolbox
[INFO] Installing yarn
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.

added 1 package, and audited 2 packages in 2s

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.13.1
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.13.1>
npm notice Run `npm install -g npm@8.13.1` to update!
npm notice
---> Installing node modules from ./yarn.lock
yarn install v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
warning supertest > superagent@7.1.6: Please downgrade to v7.1.5 if you need IE/ActiveXObject support OR upgrade to v8.0.0 as we no longer support IE and published an incorrect patch version (see https://github.com/visionmedia/superagent/issues/1731)
[3/5] Fetching packages...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
success Saved lockfile.
Done in 75.74s.
yarn run v1.22.19
$ tsc --build
Done in 14.11s.
ERROR: failed to build: toml: line 7: Key 'metadata' has already been defined.

Fixed this by running the command with --no-cache. Not sure why this is happening, but…fixed.

This is probably a bug the Heroku buildpack, according to the buildpack people. We never could quite track it down as the buildpack ecosystem is pretty complex. If it becomes a big problem, switching to a Dockerfile could help.