Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrangler is reinstalled even when it's already available #199

Closed
1000hz opened this issue Oct 17, 2023 · 12 comments · Fixed by #235
Closed

Wrangler is reinstalled even when it's already available #199

1000hz opened this issue Oct 17, 2023 · 12 comments · Fixed by #235

Comments

@1000hz
Copy link
Contributor

1000hz commented Oct 17, 2023

Currently, wrangler-action always installs wrangler as specified by the wranglerVersion input or the DEFAULT_WRANGLER_VERSION constant contained in the source. This isn't always necessary as Wrangler may have already been installed in a previous step of the workflow (e.g. if it's declared in the project's dependencies in package.json). This also makes it harder to keep the version of Wrangler used by wrangler-action and the version used locally consistent, as the user needs to manually keep wranglerVersion and package.json in sync.

Instead, we should only install Wrangler if it's not already present in the $PATH (including the package manager bin directory) OR if wranglerVersion has been explicitly provided

@peplin
Copy link

peplin commented Jan 17, 2024

+1 but also wanted to mention that not having the option to disabling this install is preventing my team from using this action because of the hugely increased runtime. The action runs yarn add wrangler and triggers linking for our entire (large) list of dependencies, and this action takes > 2 minutes. npx wrangler is ready in < 3 seconds, for comparison.

@AdiRishi
Copy link
Contributor

AdiRishi commented Feb 9, 2024

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now.
I've made a PR with a fix 👍

@TonyRL
Copy link

TonyRL commented Jun 7, 2024

@petebacondarwin Please reopen this issue due to #265.

@wqcstrong
Copy link

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now. I've made a PR with a fix 👍

@AdiRishi Thanks for your contribution. However, I am currently facing some issues with my project setup. My project uses yarn workspaces. Even though I have executed yarn install which installs wrangler@3.61.0 at the workspace root in bash ./build.sh , it seems that the check here https://github.com/cloudflare/wrangler-action/blob/main/src/index.ts#L117-L124 did not pass.

// "package.json" in workspace root 
{
  "name": "sony-pages",
  "workspaces": [
    "apps/*"
  ],
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest"
  },
  "devDependencies": {
    "@cloudflare/kv-asset-handler": "^0.3.3",
    "@cloudflare/workers-types": "^4.20240620.0",
    "lerna": "^8.1.5",
    "typescript": "^5.0.4",
    "vitest": "1.3.0",
    "wrangler": "^3.61.0"
  },
  "dependencies": {}
}
// the workflow yml
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3.6.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              ...

Do you know what could be the reason for this? Below is a screenshot of the results from my workflow execution.

image

@wqcstrong
Copy link

I've recently moved all my projects to use wrangler-action in CI. Definitely hit this quite a few times now. I've made a PR with a fix 👍

@AdiRishi Thanks for your contribution. However, I am currently facing some issues with my project setup. My project uses yarn workspaces. Even though I have executed yarn install which installs wrangler@3.61.0 at the workspace root in bash ./build.sh , it seems that the check here https://github.com/cloudflare/wrangler-action/blob/main/src/index.ts#L117-L124 did not pass.

// "package.json" in workspace root 
{
  "name": "sony-pages",
  "workspaces": [
    "apps/*"
  ],
  "version": "0.0.0",
  "private": true,
  "scripts": {
    "deploy": "wrangler deploy",
    "dev": "wrangler dev",
    "start": "wrangler dev",
    "test": "vitest"
  },
  "devDependencies": {
    "@cloudflare/kv-asset-handler": "^0.3.3",
    "@cloudflare/workers-types": "^4.20240620.0",
    "lerna": "^8.1.5",
    "typescript": "^5.0.4",
    "vitest": "1.3.0",
    "wrangler": "^3.61.0"
  },
  "dependencies": {}
}
// the workflow yml
name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3.6.0
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              ...

Do you know what could be the reason for this? Below is a screenshot of the results from my workflow execution.

image

Delete 'workspaces' field in package.json is one solution:

name: Deploy

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v4

      - name: Build
        run: |
          bash ./build.sh

+      - name: Delete 'workspaces' field
+        run: |
+          jq 'del(.workspaces)' package.json > temp.json
+          mv temp.json package.json
+          cat package.json

      - name: Deploy to cloudflare
        uses: cloudflare/wrangler-action@v3
        with:
          apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}

      - name: Lark bot notify
        run: |
          curl -X POST \
              -H "Content-Type: application/json" \
              .......

@tyteen4a03
Copy link

Also running into this issue.

@acusti
Copy link
Contributor

acusti commented Jul 11, 2024

@wqcstrong i think you are running into the issue i documented in #277. for now, i just pinned the version in my workflow file (wranglerVersion: 3.64.0), but hopefully the fix will be merged soon (cc: @tyteen4a03 in case you have the same issue)

@adamalfredsson
Copy link

adamalfredsson commented Aug 26, 2024

Same issue :(

Run cloudflare/wrangler-action@v3.7
🔍 Checking for existing Wrangler installation
  /usr/local/bin/yarn wrangler --version
  yarn run v1.22.22
  $ /home/runner/work/project/node_modules/.bin/wrangler --version
  3.13.2
  Done in 0.60s.
  ⚠️ Wrangler not found or version is incompatible. Installing...
📥 Installing Wrangler
  /usr/local/bin/yarn add wrangler@3.13.2
  yarn add v1.22.22
  error Running this command will add the dependency to the workspace root rather than the workspace itself, 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 --ignore-workspace-root-check).
  info Visit https://yarnpkg.com/en/docs/cli/add for documentation about this command.
Error: The process '/usr/local/bin/yarn' failed with exit code 1

@helle253
Copy link

helle253 commented Oct 2, 2024

Running into this issue too.

Run cloudflare/wrangler-action@v3
🔍 Checking for existing Wrangler installation
  /usr/local/bin/yarn wrangler --version
  yarn run v1.22.10
  $ /home/runner/work/site-us/site-us/nextjs/node_modules/.bin/wrangler --version
  3.79.0
  Done in 0.66s.
  ⚠️ Wrangler not found or version is incompatible. Installing...

@flyck
Copy link

flyck commented Oct 4, 2024

Ran into an issue related to this for a project with honox

Since an old version is installed, the vite build fails with a commonJS error. This error seems to be related to an issue with this older version of wrangler, and I could resolve it by specifying a current wrangler version (3.80.0):

  bun run build
  $ vite build --mode client && vite build
  failed to load config from /home/runner/work/RateThatIssue/RateThatIssue/vite.config.ts
  error during build:
  file:///home/runner/work/RateThatIssue/RateThatIssue/node_modules/@hono/vite-dev-server/dist/adapter/cloudflare.js:2
  import { getPlatformProxy } from "wrangler";
           ^^^^^^^^^^^^^^^^
  SyntaxError: Named export 'getPlatformProxy' not found. The requested module 'wrangler' is a CommonJS module, which may not support all module.exports as named exports.
  CommonJS modules can always be imported via the default export, for example using:
  
  import pkg from 'wrangler';
  const { getPlatformProxy } = pkg;

@austinorth
Copy link

Same issue here.

  /usr/local/bin/yarn wrangler --version
  yarn run v1.22.22
  $ /home/runner/work/X/X/node_modules/.bin/wrangler --version
  3.78.3
  Done in 0.89s.
  ⚠️ Wrangler not found or version is incompatible. Installing...
📥 Installing Wrangler
  /usr/local/bin/yarn add wrangler@3.13.2

@jahands
Copy link
Contributor

jahands commented Nov 18, 2024

This should be fixed now via #278

If anyone is still having this issue, please let us know.
Thanks!

@jahands jahands closed this as completed Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.