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

Fix Cloudflare Workers adapter target #3827

Merged
merged 1 commit into from
Feb 11, 2022

Conversation

pzuraq
Copy link
Contributor

@pzuraq pzuraq commented Feb 10, 2022

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.

Please don't delete this checklist! Before submitting the PR, please make sure you do the following:

  • It's really useful if your PR references an issue where it is discussed ahead of time. In many cases, features are absent for a reason. For large changes, please create an RFC: https://github.com/sveltejs/rfcs
  • This message body should clearly illustrate what problems it solves.
  • Ideally, include a test that fails without this PR but passes with it.

Unsure how to test this

Tests

  • Run the tests with pnpm test and lint the project with pnpm lint and pnpm check

Changesets

  • If your PR makes a change that should be noted in one or more packages' changelogs, generate a changeset by running pnpx changeset and following the prompts. All changesets should be patch until SvelteKit 1.0

@changeset-bot
Copy link

changeset-bot bot commented Feb 10, 2022

🦋 Changeset detected

Latest commit: 4867f2d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/adapter-cloudflare-workers Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

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.
@bluwy
Copy link
Member

bluwy commented Feb 11, 2022

Why is webpack being used to bundle stuff in cloudflare workers? The docs recommend to set type = "javascript" in the wrangler config, so webpack shouldn't be used in the first place.

@Rich-Harris Rich-Harris merged commit faefb47 into sveltejs:master Feb 11, 2022
@pzuraq
Copy link
Contributor Author

pzuraq commented Feb 11, 2022

I was taking a look at it this morning and @bluwy appears to be correct, this app was converted from a previous Cloudflare Workers app that we changed to SvelteKit. We kept parts of the workers config, including the Webpack build portion, which is no longer necessary. Removing it also fixed the issue.

So I believe this could be reverted, sorry I was just typing/about to close!

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 this pull request may close these issues.

None yet

4 participants