From faefb47f807736920832a58dcb849c5002272175 Mon Sep 17 00:00:00 2001 From: Chris Garrett Date: Fri, 11 Feb 2022 11:25:50 -0500 Subject: [PATCH] Fix Cloudflare Workers adapter target (#3827) 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. --- .changeset/wicked-terms-agree.md | 5 +++++ packages/adapter-cloudflare-workers/index.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 .changeset/wicked-terms-agree.md diff --git a/.changeset/wicked-terms-agree.md b/.changeset/wicked-terms-agree.md new file mode 100644 index 000000000000..11bc15a3d849 --- /dev/null +++ b/.changeset/wicked-terms-agree.md @@ -0,0 +1,5 @@ +--- +'@sveltejs/adapter-cloudflare-workers': patch +--- + +Fix Cloudflare adapter targets diff --git a/packages/adapter-cloudflare-workers/index.js b/packages/adapter-cloudflare-workers/index.js index e47af92ff445..ef18d54d1e23 100644 --- a/packages/adapter-cloudflare-workers/index.js +++ b/packages/adapter-cloudflare-workers/index.js @@ -55,7 +55,7 @@ export default function () { entryPoints: [`${tmp}/entry.js`], outfile: `${entrypoint}/index.js`, bundle: true, - target: 'es2020', + target: 'es2019', platform: 'browser' });