wrangler-action icon indicating copy to clipboard operation
wrangler-action copied to clipboard

Error Installing Wrangler with pnpm

Open saviski opened this issue 1 year ago β€’ 19 comments

This error started happening in the latest version

πŸ“₯ Installing Wrangler
  Running command: pnpm add [email protected]
  Error: Command failed: pnpm add [email protected]
  Error: 🚨 Action failed

saviski avatar Oct 05 '23 16:10 saviski

It seems like this could be a result of pnpm not being available in the runner environment. Are you including https://github.com/pnpm/action-setup in an earlier step of your workflow before wrangler-action?

1000hz avatar Oct 11 '23 22:10 1000hz

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/[email protected]
  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 [email protected]
  npm ERR! code EUNSUPPORTEDPROTOCOL
  Error: Command failed: npm i [email protected]
  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

AdiRishi avatar Oct 14 '23 09:10 AdiRishi

Actually I'm now 100% sure that it's a bug because it's searching in the workingDirectory. We can see this in the wrangler-action codebase

function detectPackageManager(
	workingDirectory = ".",
): PackageManagerValue | null {
	if (existsSync(path.join(workingDirectory, "package-lock.json"))) {
		return "npm";
	}
	if (existsSync(path.join(workingDirectory, "yarn.lock"))) {
		return "yarn";
	}
	if (existsSync(path.join(workingDirectory, "pnpm-lock.yaml"))) {
		return "pnpm";
	}
	if (existsSync(path.join(workingDirectory, "bun.lockb"))) {
		return "bun";
	}
	return null;
}

This is likely a seperate issue to the one being reported, should I create a new issue report?

AdiRishi avatar Oct 14 '23 09:10 AdiRishi

@AdiRishi yes, please open a new issue for that

1000hz avatar Oct 14 '23 13:10 1000hz

@AdiRishi yes, please open a new issue for that

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

AdiRishi avatar Oct 14 '23 13:10 AdiRishi

It seems like this could be a result of pnpm not being available in the runner environment. Are you including https://github.com/pnpm/action-setup in an earlier step of your workflow before wrangler-action?

Ran into the same error and I am 100% installing pnpm

      - name: Set up pnpm
        uses: pnpm/action-setup@v2
        with:
          version: 8.6.2

      - name: do a bunch of things with pnpm

      - name: Deploy
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          accountId: ${{ secrets.CF_ACCOUNT_ID }}
          command: pages deploy ./packages/portal/out --project-name=${{ vars.CF_PROJECT_NAME }}

thantos avatar Oct 17 '23 01:10 thantos

Here is the actual error (from running locally since you swallow the error :( )

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.

Going to try with a working directory.

By the way, I already have it installed at the root, would be great if the action didn't need to do it again...

thantos avatar Oct 17 '23 01:10 thantos

Which of course runs into this: https://github.com/cloudflare/wrangler-action/issues/198

This action doesn't work with pnpm workspaces.

thantos avatar Oct 17 '23 03:10 thantos

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.

thantos avatar Oct 17 '23 03:10 thantos

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.

enfipy avatar Oct 17 '23 14:10 enfipy

@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)

1000hz avatar Oct 17 '23 14:10 1000hz

Another solution to this issue here: https://github.com/cloudflare/wrangler-action/issues/198#issuecomment-1771357679

maxpetretta avatar Oct 19 '23 16:10 maxpetretta

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.

sam-goodwin avatar Nov 05 '23 02:11 sam-goodwin

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.

Unfortunately, this solution lets the action fail with

πŸš€ Running Wrangler Commands
Error: Invalid Version: * -w
Error: 🚨 Action failed

skf-funzt avatar Apr 02 '24 14:04 skf-funzt

For the workspace issue, an easy workaround is to just add a step right before wrangler-action:

- run: echo "ignore-workspace-root-check=true" >> .npmrc

If you don't have any other pnpm adds later there's no need to remove it in a workflow.

Ambroos avatar Apr 23 '24 16:04 Ambroos

Since v3.6.0, released a few hours ago, the action will reuse an existing Wrangler installation. You can just pre-install your favourite wrangler version and this is no longer an issue: https://github.com/cloudflare/wrangler-action/releases/tag/v3.6.0

Update: the fix that fixed this in v3.6.0 was reverted in v3.6.1 because it had some breaking side effects if you use npm, but it's fine if you use pnpm. We pinned the action to v3.6.0 in our repo to keep the fix: uses: cloudflare/[email protected]

Ambroos avatar May 23 '24 20:05 Ambroos

Is anyone else here having this issue when setting packageManager: pnpm and also setting workingDirectory? https://github.com/cloudflare/workers-sdk/issues/6224

IanVS avatar Jul 26 '24 12:07 IanVS

I am still having problem doing, but and what if I am using bun as the package manager?

broisnischal avatar Aug 05 '24 14:08 broisnischal

Would --ignore-workspaces break other functionality? https://github.com/orgs/pnpm/discussions/4735#discussioncomment-2770033

stevefrench39 avatar Aug 18 '24 14:08 stevefrench39

Workaround that works for me:

  1. Install the wrangler to the root package.json of your workspace
  2. Skip wranglerVersion in cloudflare/wrangler-action@v3:
    - name: Publish project to Cloudflare Pages
      uses: cloudflare/wrangler-action@v3
      with:
        apiToken: ${{ inputs.cloudflare-api-token }}
        accountId: ${{ inputs.cloudflare-account-id }}
        gitHubToken: ${{ inputs.github-token }}
        command: pages deploy ${{ inputs.assets-directory }} --project-name=${{ inputs.project }} --branch=${{ inputs.branch }}
  1. The cloudflare/wrangler-action@v3 will get an installed version of the wrangler from the package.json Image

VoloshchenkoAl avatar Feb 06 '25 16:02 VoloshchenkoAl