`fly launch` fails with pnpm workspace

TLDR;

fly launch was failing in my pnpm workspace (monorepo) when running it either inside the app package directory or from the monorepo root level. Creating a .npmrc file at the root with ignore-workspace-root-check=true solved the issue.

This should not be necessary and should be treated as a bug in my opinion. The fly cli should add the --workspace-root flag (or -w) in pnpm add -D @flydotio/dockerfile@latest.


Hi

I’m new to fly.io and I’m currently having a pretty hard time trying to launch a Node.js app. That app is a package inside a monorepo managed with pnpm workspace. I want to call the command from my local machine and eventually run it from a github workflow.

The documentation provides information about setting up fly.io for a monorepo (Monorepo and multi-environment deployments · Fly Docs), but it only refers to fly deploy ./path/to/app, but what about launching an app? Calling fly launch ./path/to/app gives me an unknown command error and I don’t want to use fly deploy seems I want fly to set my project, provides the initial configuration.

So first, I tried to call fly launch from inside the app package directory. I was able to tweak my settings in the browser, the app and database were created in fly.io, but in the installation step, and I was getting this error:

npm error code 127
npm error path /Users/my/monorepo/node_modules/.pnpm/uuid@10.0.0/node_modules/uuid
npm error command failed
npm error command sh -c husky install
npm error sh: husky: command not found

because it’s a pnpm workspace and husky would be installed at the root level of the monorepo.

The second thing I tried was to call fly launch from the root level of the monorepo and add a start script to the root package.json that simply calls the start script of the app package. It was working at the beginning: app + db created, then the installation ended up creating .github/workflows/fly-deploy.yml shortly before failing again at this stage:

Postgres cluster my-database is now attached to my-app
The following secret was added to my-app:
DATABASE_URL=postgres://my_app:foo
Postgres cluster my-database is now attached to my-app
installing: pnpm add -D @flydotio/dockerfile@latest

ERR_PNPM_ADDING_TO_ROOT Running this command will add the dependency to the workspace root, which might not be what you want - if you really meant it, make it explicit by running this command again with the -w flag (or --workspace-root). If you don't want to see this warning anymore, you may set the ignore-workspace-root-check setting to true.
Error: failed to install @flydotio/dockerfile: exit status 1

EDIT:

I created a .npmrc file with ignore-workspace-root-check=true as content which fixed the issue. Then the installation went through and the Docker files and fly.toml were created.

So I found a solution after all, but I had a bad first experience. I wanted to share it in case it can help improving that journey.

Care to contribute? Here’s the code that produces the Dockerfile: GitHub - fly-apps/dockerfile-node: Dockerfile generator for Node.js

Sure, I would be happy to. Let me have a look at the repo.

@rubys The repository you linked is the one for @flydotio/dockerfile, but the bug is coming from the cli. It is written in Go unfortunately and I’m not a Go developer, but I gave it a shot anyway since the change is so straightforward:

1 Like

Looks good. I merged the change. It should be released in ~ 6 hours. Thanks!

2 Likes