-
Notifications
You must be signed in to change notification settings - Fork 868
fix: detect service worker entrypoints correctly #2396
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
Conversation
jimmed
commented
Dec 12, 2022
- Fixes 🐛 BUG: Usage of "typeof module" causes error "The uploaded script has no registered event handlers. [code: 10068]" #1668
|
A wrangler prerelease is available for testing. You can install this latest build in your project with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/runs/3677216220/npm-package-wrangler-2396 You can reference the automatically updated head of this PR with: npm install --save-dev https://prerelease-registry.devprod.cloudflare.dev/prs/2396/npm-package-wrangler-2396 Or you can use npx https://prerelease-registry.devprod.cloudflare.dev/runs/3677216220/npm-package-wrangler-2396 dev path/to/script.js Additional artifacts:npm install https://prerelease-registry.devprod.cloudflare.dev/runs/3677216220/npm-package-cloudflare-pages-shared-2396 |
Hey! 👋 I've just tried this PR out with the reproduction locally and it doesn't appear to fix the issue. 😕 I had a bit more of a look into this though, and I think the right fix would be to remove the |
Apologies -- I didn't have time for a proper write-up of this. In order to use the I've been deploying successfully using this change (via patch-package). |
Wrangler automatically detects whether your code is a `modules` or `service-worker` format Worker based on the presence of a `default` `export`. This check currently works by building your entrypoint with `esbuild` and looking at the output metafile. Previously, we were passing `format: "esm"` to `esbuild` when performing this check, which enables *format conversion*. This may introduce `export default` into the built code, even if it wasn't there to start with, resulting in incorrect format detections. This change removes `format: "esm"` which disables format conversion when bundling is disabled: https://esbuild.github.io/api/#format. We may want to use a package like `es-module-lexer` in the future, but this issue is affecting users, and this is probably the simplest fix. Closes #1668 Closes #2396 Ref #2737
Wrangler automatically detects whether your code is a `modules` or `service-worker` format Worker based on the presence of a `default` `export`. This check currently works by building your entrypoint with `esbuild` and looking at the output metafile. Previously, we were passing `format: "esm"` to `esbuild` when performing this check, which enables *format conversion*. This may introduce `export default` into the built code, even if it wasn't there to start with, resulting in incorrect format detections. This change removes `format: "esm"` which disables format conversion when bundling is disabled: https://esbuild.github.io/api/#format. We may want to use a package like `es-module-lexer` in the future, but this issue is affecting users, and this is probably the simplest fix. Closes #1668 Closes #2396 Ref #2737