wrangler-action: Error Installing Wrangler with pnpm

This error started happening in the latest version

📥 Installing Wrangler
  Running command: pnpm add wrangler@3.5.1
  Error: Command failed: pnpm add wrangler@3.5.1
  Error: 🚨 Action failed

About this issue

  • Original URL
  • State: open
  • Created 9 months ago
  • Comments: 15 (6 by maintainers)

Most upvoted comments

@thantos thanks for investigating. It looks like there are two distinct problems here:

  • The missing -w flag in the install command causes pnpm to error
  • Package manager inference fails when workspaces are used (#198)

I’ll keep this issue open to track the first problem. Installation error stdout being swallowed should be addressed by #171. I’ll also open a new issue to track installing wrangler only when it’s not already installed. (#199)

Update: I was able to get by this with a hack

wranglerVersion: "* -w"

This uses the existing version of wrangler in the root pnpm and injects the -w needed to bypass the PNPM workspace root error.

This workaround isn’t working for me.

I have opened a PR with an attempt to fix this: https://github.com/cloudflare/wrangler-action/pull/207

@1000hz let me know if my approach is on the right track.

I was able to work around this issue with a pretty simple change, just by setting packageManager: pnpm near the workingDirectory property:

- uses: pnpm/action-setup@v2
  with:
    version: 8.9.0
- uses: cloudflare/wrangler-action@v3
  with:
    apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
    workingDirectory: ./<PATH_TO_PACKAGE>/
    environment: production
    packageManager: pnpm

The issue indeed is because of getPackageManager function tries to retrieve packageManager from detectPackageManager(workingDirectory), and when workingDirectory is a subdirectory of workspace (e.g. without pnpm-lock.yaml) - it results in an error. So explicitly setting packageManager: pnpm - solves this issue.

P.S: Also, I think it’s a good idea to mention this in the docs or troubleshooting, as nowadays many projects use workspaces.

@AdiRishi yes, please open a new issue for that

Done - https://github.com/cloudflare/wrangler-action/issues/198

@AdiRishi yes, please open a new issue for that

I just ran into this myself. For me I think the special case was that I’m using the workingDirectory property

- name: Deploy apex-gateway
  uses: cloudflare/wrangler-action@v3
  with:
    accountId: ${{ secrets.CF_ACCOUNT_ID || secrets.CLOUDFLARE_ACCOUNT_ID }}
    apiToken: ${{ secrets.CF_API_TOKEN || secrets.CLOUDFLARE_API_TOKEN }}
    workingDirectory: 'workers/apex-gateway'
    command: 'deploy'

My suspicion is that it is looking for pnpm-lock.yaml which doesn’t exist when running in the subdirectory. To be clear, this is running in a monorepo setup (using turborepo). The exact error message is

Run cloudflare/wrangler-action@v3.3.1
  with:
    accountId: ***
    apiToken: ***
    workingDirectory: workers/apex-gateway
    command: deploy
    quiet: false
  env:
    TURBO_TOKEN: ***
    TURBO_REMOTE_CACHE_SIGNATURE_KEY: ***
    TURBO_TEAM: team_tiptop
    TURBO_API: ***
    GITHUB_SHA: ***
    CLOUDFLARE_ACCOUNT_ID: ***
    CLOUDFLARE_API_TOKEN: ***
    NODE_ENV: production
    PNPM_HOME: /home/runner/setup-pnpm/node_modules/.bin
📥 Installing Wrangler
  Running command: npm i wrangler@3.5.1
  npm ERR! code EUNSUPPORTEDPROTOCOL
  Error: Command failed: npm i wrangler@3.5.1
  npm ERR! code EUNSUPPORTEDPROTOCOL
  npm ERR! Unsupported URL Type "workspace:": workspace:*
  
  npm ERR! A complete log of this run can be found in: /home/runner/.npm/_logs/2023-10-14T09_39_26_137Z-debug-0.log
  
  npm ERR! Unsupported URL Type "workspace:": workspace:*

  npm ERR! A complete log of this run can be found in: /home/runner/.npm/_logs/2023-10-14T09_39_26_137Z-debug-0.log
  Error: 🚨 Action failed