cloudflare / workers-sdk

โ›…๏ธ Home to Wrangler, the CLI for Cloudflare Workersยฎ
https://developers.cloudflare.com/workers/
Apache License 2.0
2.56k stars 653 forks source link

๐Ÿ› BUG: โœ˜ [ERROR] Could not resolve "@cloudflare/pages-plugin-sentry" #1925

Closed aensley closed 1 year ago

aensley commented 1 year ago

What version of Wrangler are you using?

2.1.6

What operating system are you using?

Windows (Git Bash/MINGW)

Describe the Bug

Summary

I am unable to resolve any packages in Cloudflare workers despite them being listed on https://workers.cloudflare.com/works and working locally through wrangler.

I followed the official guide to integrate Sentry as middleware.

Repo/branch

https://github.com/aensley/liturgy-day/tree/add-sentry-2

Source

https://github.com/aensley/liturgy-day/blob/12f431856ec80533f29ffa5bc08320ad6dd7d464/functions/_middleware.ts#L1-L8

Build Error

09:39:43.463 | Cloning repository...
-- | --
09:39:44.397 | From https://github.com/aensley/liturgy-day
09:39:44.397 | * branch            12f431856ec80533f29ffa5bc08320ad6dd7d464 -> FETCH_HEAD
09:39:44.397 | ย 
09:39:44.443 | HEAD is now at 12f4318 add wrangler?
09:39:44.443 | ย 
09:39:44.551 | ย 
09:39:44.573 | Success: Finished cloning repository files
09:39:45.069 | No build command specified. Skipping build step.
09:39:45.559 | ๐Ÿšง 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
09:39:45.625 | โœ˜ [ERROR] Could not resolve "@cloudflare/pages-plugin-sentry"
09:39:45.625 | ย 
09:39:45.625 | ../../../buildhome/repo/functions/_middleware.ts:1:25:
09:39:45.625 | 1 โ”‚ import sentryPlugin from '@cloudflare/pages-plugin-sentry'
09:39:45.626 | โ•ต                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
09:39:45.626 | ย 
09:39:45.626 | You can mark the path "@cloudflare/pages-plugin-sentry" as external to exclude it from the bundle, which will remove this error.
09:39:45.627 | ย 
09:39:45.630 | 1 error(s) and 0 warning(s) when compiling Worker.
09:39:45.631 | ย 
09:39:45.718 | โœ˜ [ERROR] Build failed with 1 error:
09:39:45.718 | ย 
09:39:45.718 | ../../../buildhome/repo/functions/_middleware.ts:1:25: ERROR: Could not resolve "@cloudflare/pages-plugin-sentry"
09:39:45.718 | ย 
09:39:45.718 | ย 
09:39:45.718 | If you think this is a bug then please create an issue at https://github.com/cloudflare/wrangler2/issues/new/choose
09:39:45.727 | Failed building Pages Functions from /functions.
09:39:46.537 | Failed: an internal error occurred

Local output (successful)

image

me@my-computer MINGW64 ~/Workspaces/liturgy-day (add-sentry-2)
$ npx wrangler pages dev src --binding SENTRY_DSN="https://xxxxxxxxxxxxx@xxxxxxx.ingest.sentry.io/xxxxxxxxx" --binding ENVIRONMENT="local"
๐Ÿšง 'wrangler pages <command>' is a beta command. Please report any issues to https://github.com/cloudflare/wrangler2/issues/new/choose
Compiling worker to "C:\Users\me\AppData\Local\Temp\functionsWorker-0.9120506640895183.js"...
Compiled Worker successfully.
โ–ฒ [WARNING] Passing --inspect is unnecessary, now you can always connect to devtools.

โ•ญโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฎ
โ”‚ [b] open a browser, [d] open Devtools, [c] clear console, [x] to exit  โ”‚
โ•ฐโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ•ฏ
Debugger listening on ws://0.0.0.0:9229/972d75ea-2273-4625-8023-a5817c6a81ab
For help, see: https://nodejs.org/en/docs/inspector
[pages:wrn] Parsed 2 valid header rules.
[pages:wrn] Service bindings are experimental. There may be breaking changes in the future.
[pages:inf] Worker reloaded! (195.16KiB)
[pages:inf] Listening on 0.0.0.0:8788
[pages:inf] Updated `Request.cf` object cache!
GET /api/day/2022-09-26 200 OK (19.75ms)
aensley commented 1 year ago

Hi @nevikashah, do you have any ideas about what could be causing my issue?

davidmurdoch commented 1 year ago

Same issue here, but with @cloudflare/kv-asset-handler, but only when using cloudflare/wrangler-action@2.0.0

thexeos commented 1 year ago

Although unrelated to https://github.com/cloudflare/wrangler2/labels/pages doing import '@cloudflare/workers-types' (aka importing worker types locally, rather than globally via tsconfig.json) also triggers this error:

  You can mark the path "@cloudflare/workers-types" as external to exclude it from the 
  bundle, which will remove this error.

X [ERROR] Build failed with 1 error:

  src/worker.ts:7:7: ERROR: Could not resolve "@cloudflare/workers-types"
aensley commented 1 year ago

Hi @nevikashah, any updates?

harikrishnan83 commented 1 year ago

I was having the same issue with @cloudflare/kv-asset-handler, I have temporarily resolved this by adding a precommand to install @cloudflare/kv-asset-handler, is there a better approach? Thanks.

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    name: Deploy
    steps:
      - uses: actions/checkout@v3
      - name: Publish
        uses: cloudflare/wrangler-action@2.0.0
        with:
          apiToken: ${{ secrets.CF_API_TOKEN }}
          preCommands: npm install @cloudflare/kv-asset-handler@0.2.0
          command: publish
jrf0110 commented 1 year ago

Hey there, @aensley - did you ever get this resolved? I followed your reproduction repo and it seems like your Github Actions are running smoothly

aensley commented 1 year ago

@jrf0110 No, this is not resolved. My actions are working on other branches that exclude this package. Every build that references the cloudflare-maintained Sentry package still fails with the error above. I have received no help in resolving this.

aensley commented 1 year ago

I have finally resolved this issue. The problem was that the build command configuration in Cloudflare Pages did not include npm install. I always thought this was run transparently in the background for NPM sites since I never had to explicitly add it before.