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
===> DETECTING
heroku/nodejs-engine 0.8.2
heroku/nodejs-yarn 0.2.2
heroku/procfile 0.6.2
===> 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: >=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: <https://github.com/npm/cli/releases/tag/v8.7.0>
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.