Skip to content

Commit

Permalink
Fix Cloudflare Workers adapter target (#3827)
Browse files Browse the repository at this point in the history
When attempting to upload a SvelteKit app which contains modern ES
features such as optional chaining or nullish coalescing, workers is
unable to parse the built output.

```
Module parse failed: Unexpected token (13066:47)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|       if (typeof window !== "undefined") {
|         const windowAny = window;
>         const dataLayer = windowAny.dataLayer ?? [];
|         windowAny.dataLayer = dataLayer;
|         gtag = function() {
Error: webpack returned an error. You may be able to resolve this issue by running npm install
```

I could not find any official documentation of what version of ES
workers support, but ES2020 is the year that nullish coalescing was
introduced, and setting it to ES2019 appears to fix the issue.
  • Loading branch information
pzuraq authored Feb 11, 2022
1 parent 691363b commit faefb47
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/wicked-terms-agree.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/adapter-cloudflare-workers': patch
---

Fix Cloudflare adapter targets
2 changes: 1 addition & 1 deletion packages/adapter-cloudflare-workers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function () {
entryPoints: [`${tmp}/entry.js`],
outfile: `${entrypoint}/index.js`,
bundle: true,
target: 'es2020',
target: 'es2019',
platform: 'browser'
});

Expand Down

0 comments on commit faefb47

Please sign in to comment.